diff --git a/tests/testthat/test-db_joins.R b/tests/testthat/test-db_joins.R index a7c95885..10415c2c 100644 --- a/tests/testthat/test-db_joins.R +++ b/tests/testthat/test-db_joins.R @@ -1,28 +1,6 @@ test_that("*_join() works with character `by` and `na_by`", { for (conn in get_test_conns()) { - # Define two test datasets - x <- get_table(conn, "__mtcars") |> - dplyr::select(name, mpg, cyl, hp, vs, am, gear, carb) - - y <- get_table(conn, "__mtcars") |> - dplyr::select(name, drat, wt, qsec) - - - # Test the implemented joins - q <- dplyr::left_join(x, y, by = "name") |> dplyr::collect() - qr <- dplyr::left_join(dplyr::collect(x), dplyr::collect(y), by = "name") - expect_equal(q, qr) - - q <- dplyr::right_join(x, y, by = "name") |> dplyr::collect() - qr <- dplyr::right_join(dplyr::collect(x), dplyr::collect(y), by = "name") - expect_equal(q, qr) - - q <- dplyr::inner_join(x, y, by = "name") |> dplyr::collect() - qr <- dplyr::inner_join(dplyr::collect(x), dplyr::collect(y), by = "name") - expect_equal(q, qr) - - # Create two more synthetic test data set with NA data # First test case @@ -144,3 +122,67 @@ test_that("*_join() works with `dplyr::join_by()`", { connection_clean_up(conn) } }) + + +test_that("*_join() does not break any dplyr joins", { + for (conn in get_test_conns()) { + + # Define two test datasets + x <- get_table(conn, "__mtcars") |> + dplyr::select(name, mpg, cyl, hp, vs, am, gear, carb) + + y <- get_table(conn, "__mtcars") |> + dplyr::select(name, drat, wt, qsec) + + # Test the standard joins + # left_join + qr <- dplyr::left_join(dplyr::collect(x), dplyr::collect(y), by = "name") + q <- dplyr::left_join(x, y, by = "name") |> dplyr::collect() + expect_equal(q, qr) + + q <- dplyr::left_join(x, y, by = dplyr::join_by(x$name == y$name)) |> dplyr::collect() + expect_equal(q, qr) + + # right_join + qr <- dplyr::right_join(dplyr::collect(x), dplyr::collect(y), by = "name") + q <- dplyr::right_join(x, y, by = "name") |> dplyr::collect() + expect_equal(q, qr) + + q <- dplyr::right_join(x, y, by = dplyr::join_by(x$name == y$name)) |> dplyr::collect() + expect_equal(q, qr) + + # inner_join + qr <- dplyr::inner_join(dplyr::collect(x), dplyr::collect(y), by = "name") + q <- dplyr::inner_join(x, y, by = "name") |> dplyr::collect() + expect_equal(q, qr) + + q <- dplyr::inner_join(x, y, by = dplyr::join_by(x$name == y$name)) |> dplyr::collect() + expect_equal(q, qr) + + # full_join + qr <- dplyr::full_join(dplyr::collect(x), dplyr::collect(y), by = "name") + q <- dplyr::full_join(x, y, by = "name") |> dplyr::collect() + expect_equal(q, qr) + + q <- dplyr::full_join(x, y, by = dplyr::join_by(x$name == y$name)) |> dplyr::collect() + expect_equal(q, qr) + + # semi_join + qr <- dplyr::semi_join(dplyr::collect(x), dplyr::collect(y), by = "name") + q <- dplyr::semi_join(x, y, by = "name") |> dplyr::collect() + expect_equal(q, qr) + + q <- dplyr::semi_join(x, y, by = dplyr::join_by(x$name == y$name)) |> dplyr::collect() + expect_equal(q, qr) + + # anti_join + qr <- dplyr::anti_join(dplyr::collect(x), dplyr::collect(y), by = "name") + q <- dplyr::anti_join(x, y, by = "name") |> dplyr::collect() + expect_equal(q, qr) + + q <- dplyr::anti_join(x, y, by = dplyr::join_by(x$name == y$name)) |> dplyr::collect() + expect_equal(q, qr) + + connection_clean_up(conn) + } +})