Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions r/R/dplyr-join.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ handle_join_by <- function(by, x, y) {
if (is.null(by)) {
return(set_names(intersect(names(x), names(y))))
}
if (inherits(by, "dplyr_join_by")) {
if (!all(by$condition == "==" & by$filter == "none")) {
abort(
paste0(
"Inequality conditions and helper functions ",
"are not supported in `join_by()` expressions."
)
)
}
by <- set_names(by$y, by$x)
}
stopifnot(is.character(by))
if (is.null(names(by))) {
by <- set_names(by)
Expand Down
50 changes: 50 additions & 0 deletions r/tests/testthat/test-dplyr-join.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@ test_that("left_join `by` args", {
)
})

test_that("left_join with join_by", {
# only run this test in newer versions of dplyr that include `join_by()`
skip_if_not(packageVersion("dplyr") >= "1.0.99.9000")

compare_dplyr_binding(
.input %>%
left_join(to_join, join_by(some_grouping)) %>%
collect(),
left
)
compare_dplyr_binding(
.input %>%
left_join(
to_join %>%
rename(the_grouping = some_grouping),
join_by(some_grouping == the_grouping)
) %>%
collect(),
left
)

compare_dplyr_binding(
.input %>%
rename(the_grouping = some_grouping) %>%
left_join(
to_join,
join_by(the_grouping == some_grouping)
) %>%
collect(),
left
)
})

test_that("join two tables", {
expect_identical(
arrow_table(left) %>%
Expand Down Expand Up @@ -136,6 +169,23 @@ test_that("Error handling", {
)
})

test_that("Error handling for unsupported expressions in join_by", {
# only run this test in newer versions of dplyr that include `join_by()`
skip_if_not(packageVersion("dplyr") >= "1.0.99.9000")

expect_error(
arrow_table(left) %>%
left_join(to_join, join_by(some_grouping >= some_grouping)),
"not supported"
)

expect_error(
arrow_table(left) %>%
left_join(to_join, join_by(closest(some_grouping >= some_grouping))),
"not supported"
)
})

# TODO: test duplicate col names
# TODO: casting: int and float columns?

Expand Down