forked from tidyverse/dbplyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery-semi-join.R
67 lines (59 loc) · 1.59 KB
/
query-semi-join.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#' @export
#' @rdname sql_build
semi_join_query <- function(x,
y,
vars,
anti = FALSE,
by = NULL,
where = NULL,
na_matches = FALSE) {
structure(
list(
x = x,
y = y,
vars = vars,
anti = anti,
by = by,
where = where,
na_matches = na_matches
),
class = c("semi_join_query", "query")
)
}
#' @export
print.semi_join_query <- function(x, ...) {
cat_line("<SQL ", if (x$anti) "ANTI" else "SEMI", " JOIN>")
cat_line("By:")
cat_line(indent(paste0(x$by$x, "-", x$by$y)))
if (length(x$where)) {
cat_line("Where:")
where <- purrr::map_chr(x$where, as_label)
cat_line(indent(paste0(where)))
}
cat_line("X:")
cat_line(indent_print(x$x))
cat_line("Y:")
cat_line(indent_print(x$y))
}
#' @export
sql_render.semi_join_query <- function(query,
con = NULL,
...,
sql_options = NULL,
subquery = FALSE,
lvl = 0) {
from_x <- sql_render(query$x, con, ..., subquery = TRUE, lvl = lvl + 1)
from_y <- sql_render(query$y, con, ..., subquery = TRUE, lvl = lvl + 1)
dbplyr_query_semi_join(
con,
from_x,
from_y,
vars = query$vars,
anti = query$anti,
by = query$by,
where = query$where,
lvl = lvl
)
}
#' @export
flatten_query.semi_join_query <- flatten_query_2_tables