Skip to content

Commit

Permalink
Add sql_join_suffix() generic
Browse files Browse the repository at this point in the history
Fixes #214
  • Loading branch information
hadley committed Sep 24, 2020
1 parent 74260eb commit 6e64685
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
@@ -1,5 +1,7 @@
# dbplyr (development version)

* New `sql_join_suffix()` allows backends to control the default suffixes used (#254).

* `distinct()` no longer duplicates column if grouped (#354).

* `mutate()` grouping variables no longer generates a downstream error (#396)
Expand Down
10 changes: 10 additions & 0 deletions R/backend-.R
Expand Up @@ -524,3 +524,13 @@ sql_save_query.DBIConnection <- function(con, sql, name, temporary = TRUE, ...)
con = con
)
}

#' @rdname db_sql
#' @export
sql_join_suffix <- function(con, ...) {
UseMethod("sql_join_suffix")
}
#' @export
sql_join_suffix.DBIConnection <- function(con, ...) {
c(".x", ".y")
}
11 changes: 6 additions & 5 deletions R/verb-joins.R
Expand Up @@ -68,7 +68,7 @@ NULL
#' @export
#' @importFrom dplyr inner_join
inner_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
suffix = c(".x", ".y"),
suffix = NULL,
auto_index = FALSE, ...,
sql_on = NULL) {

Expand All @@ -88,7 +88,7 @@ inner_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
#' @export
#' @importFrom dplyr left_join
left_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
suffix = c(".x", ".y"),
suffix = NULL,
auto_index = FALSE, ...,
sql_on = NULL) {

Expand All @@ -108,7 +108,7 @@ left_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
#' @export
#' @importFrom dplyr right_join
right_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
suffix = c(".x", ".y"),
suffix = NULL,
auto_index = FALSE, ...,
sql_on = NULL) {

Expand All @@ -128,7 +128,7 @@ right_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
#' @export
#' @importFrom dplyr full_join
full_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,
suffix = c(".x", ".y"),
suffix = NULL,
auto_index = FALSE, ...,
sql_on = NULL) {

Expand Down Expand Up @@ -182,7 +182,7 @@ anti_join.tbl_lazy <- function(x, y, by = NULL, copy = FALSE,


add_op_join <- function(x, y, type, by = NULL, sql_on = NULL, copy = FALSE,
suffix = c(".x", ".y"),
suffix = NULL,
auto_index = FALSE) {

if (!is.null(sql_on)) {
Expand All @@ -200,6 +200,7 @@ add_op_join <- function(x, y, type, by = NULL, sql_on = NULL, copy = FALSE,
indexes = if (auto_index) list(by$y)
)

suffix <- suffix %||% sql_join_suffix(x$src$con, suffix)
vars <- join_vars(op_vars(x), op_vars(y), type = type, by = by, suffix = suffix)

x$ops <- op_double("join", x, y, args = list(
Expand Down

0 comments on commit 6e64685

Please sign in to comment.