diff --git a/DESCRIPTION b/DESCRIPTION index 553008094..560608c26 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: duckdb Title: DBI Package for the DuckDB Database Management System -Version: 1.1.0 +Version: 1.1.1 Authors@R: c( person("Hannes", "Mühleisen", , "hannes@cwi.nl", role = "aut", comment = c(ORCID = "0000-0001-8552-0029")), diff --git a/src/reltoaltrep.cpp b/src/reltoaltrep.cpp index 76d9531b8..dca93fbb0 100644 --- a/src/reltoaltrep.cpp +++ b/src/reltoaltrep.cpp @@ -94,6 +94,7 @@ struct AltrepRelationWrapper { } // We need to temporarily allow a deeper execution stack + // https://github.com/duckdb/duckdb-r/issues/101 auto old_depth = rel->context.GetContext()->config.max_expression_depth; rel->context.GetContext()->config.max_expression_depth = old_depth * 2; res = rel->Execute(); diff --git a/tests/testthat/test-rel_api.R b/tests/testthat/test-rel_api.R index 677d4e8a9..3288a380d 100644 --- a/tests/testthat/test-rel_api.R +++ b/tests/testthat/test-rel_api.R @@ -4,19 +4,25 @@ test_that("relational anti_join(join_by(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "anti_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "anti_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "anti_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "anti_join" rel4 <- rel_set_alias(rel3, "rhs") + "anti_join" rel5 <- rel_project( rel2, list( @@ -37,6 +43,7 @@ test_that("relational anti_join(join_by(a)) order-preserving", { } ) ) + "anti_join" rel6 <- rel_join( rel5, rel4, @@ -45,7 +52,9 @@ test_that("relational anti_join(join_by(a)) order-preserving", { ), "anti" ) + "anti_join" rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5))) + "anti_join" rel8 <- rel_project( rel7, list( @@ -63,7 +72,7 @@ test_that("relational anti_join(join_by(a)) order-preserving", { ) rel8 out <- rel_to_altrep(rel8) - expect_equal( + expect_identical( out, data.frame(a = 1L, b = 2) ) @@ -74,19 +83,25 @@ test_that("relational anti_join(join_by(a)) order-preserving", { test_that("relational anti_join(join_by(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "anti_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "anti_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "anti_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "anti_join" rel4 <- rel_set_alias(rel3, "rhs") + "anti_join" rel5 <- rel_join( rel2, rel4, @@ -95,10 +110,11 @@ test_that("relational anti_join(join_by(a)) order-enforcing", { ), "anti" ) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("a"), expr_reference("b"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(a = 1L, b = 2) ) @@ -109,14 +125,16 @@ test_that("relational anti_join(join_by(a)) order-enforcing", { test_that("relational arrange() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) rel1 out <- rel_to_altrep(rel1) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -125,11 +143,14 @@ test_that("relational arrange() order-preserving", { test_that("relational arrange(a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_project( rel1, list( @@ -155,7 +176,9 @@ test_that("relational arrange(a) order-preserving", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("a"), expr_reference("___row_number"))) + "arrange" rel4 <- rel_project( rel3, list( @@ -178,7 +201,7 @@ test_that("relational arrange(a) order-preserving", { ) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -187,11 +210,14 @@ test_that("relational arrange(a) order-preserving", { test_that("relational arrange(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_project( rel1, list( @@ -217,7 +243,9 @@ test_that("relational arrange(g) order-preserving", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("___row_number"))) + "arrange" rel4 <- rel_project( rel3, list( @@ -240,7 +268,7 @@ test_that("relational arrange(g) order-preserving", { ) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -249,11 +277,14 @@ test_that("relational arrange(g) order-preserving", { test_that("relational arrange(g, a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_project( rel1, list( @@ -279,10 +310,12 @@ test_that("relational arrange(g, a) order-preserving", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("g"), expr_reference("a"), expr_reference("___row_number")) ) + "arrange" rel4 <- rel_project( rel3, list( @@ -305,7 +338,7 @@ test_that("relational arrange(g, a) order-preserving", { ) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -314,11 +347,14 @@ test_that("relational arrange(g, a) order-preserving", { test_that("relational arrange(a, g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_project( rel1, list( @@ -344,10 +380,12 @@ test_that("relational arrange(a, g) order-preserving", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("g"), expr_reference("___row_number")) ) + "arrange" rel4 <- rel_project( rel3, list( @@ -370,7 +408,7 @@ test_that("relational arrange(a, g) order-preserving", { ) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -381,19 +419,23 @@ test_that("relational arrange(a, g) order-preserving", { test_that("relational arrange() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -402,19 +444,23 @@ test_that("relational arrange() order-enforcing", { test_that("relational arrange(a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_order(rel1, list(expr_reference("a"))) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -423,19 +469,23 @@ test_that("relational arrange(a) order-enforcing", { test_that("relational arrange(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_order(rel1, list(expr_reference("g"))) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -444,19 +494,23 @@ test_that("relational arrange(g) order-enforcing", { test_that("relational arrange(g, a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_order(rel1, list(expr_reference("g"), expr_reference("a"))) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -465,19 +519,23 @@ test_that("relational arrange(g, a) order-enforcing", { test_that("relational arrange(a, g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "arrange" rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" rel2 <- rel_order(rel1, list(expr_reference("a"), expr_reference("g"))) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -488,12 +546,15 @@ test_that("relational arrange(a, g) order-enforcing", { test_that("relational count() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list(), @@ -507,7 +568,7 @@ test_that("relational count() order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(n = 6L) ) @@ -516,12 +577,15 @@ test_that("relational count() order-preserving", { test_that("relational count(a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -539,6 +603,7 @@ test_that("relational count(a) order-preserving", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -551,7 +616,7 @@ test_that("relational count(a) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) @@ -560,12 +625,15 @@ test_that("relational count(a) order-preserving", { test_that("relational count(b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -583,6 +651,7 @@ test_that("relational count(b) order-preserving", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -595,7 +664,7 @@ test_that("relational count(b) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(b = 2, n = 6L) ) @@ -604,12 +673,15 @@ test_that("relational count(b) order-preserving", { test_that("relational count(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -627,6 +699,7 @@ test_that("relational count(g) order-preserving", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -639,7 +712,7 @@ test_that("relational count(g) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(g = 1:3, n = 1:3) ) @@ -648,12 +721,15 @@ test_that("relational count(g) order-preserving", { test_that("relational count(g, a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -676,6 +752,7 @@ test_that("relational count(g, a) order-preserving", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -693,7 +770,7 @@ test_that("relational count(g, a) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) @@ -702,12 +779,15 @@ test_that("relational count(g, a) order-preserving", { test_that("relational count(b, g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -730,6 +810,7 @@ test_that("relational count(b, g) order-preserving", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -747,7 +828,7 @@ test_that("relational count(b, g) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(b = rep(2, 3L), g = 1:3, n = 1:3) ) @@ -758,12 +839,15 @@ test_that("relational count(b, g) order-preserving", { test_that("relational count() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list(), @@ -775,10 +859,11 @@ test_that("relational count() order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("n"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(n = 6L) ) @@ -787,12 +872,15 @@ test_that("relational count() order-enforcing", { test_that("relational count(a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -810,6 +898,7 @@ test_that("relational count(a) order-enforcing", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -820,10 +909,11 @@ test_that("relational count(a) order-enforcing", { } ) ) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("n"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) @@ -832,12 +922,15 @@ test_that("relational count(a) order-enforcing", { test_that("relational count(b) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -855,6 +948,7 @@ test_that("relational count(b) order-enforcing", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -865,10 +959,11 @@ test_that("relational count(b) order-enforcing", { } ) ) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("b"), expr_reference("n"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(b = 2, n = 6L) ) @@ -877,12 +972,15 @@ test_that("relational count(b) order-enforcing", { test_that("relational count(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -900,6 +998,7 @@ test_that("relational count(g) order-enforcing", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -910,10 +1009,11 @@ test_that("relational count(g) order-enforcing", { } ) ) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("g"), expr_reference("n"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(g = 1:3, n = 1:3) ) @@ -922,12 +1022,15 @@ test_that("relational count(g) order-enforcing", { test_that("relational count(g, a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -950,6 +1053,7 @@ test_that("relational count(g, a) order-enforcing", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -965,13 +1069,14 @@ test_that("relational count(g, a) order-enforcing", { } ) ) + "arrange" rel4 <- rel_order( rel3, list(expr_reference("g"), expr_reference("a"), expr_reference("n")) ) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) @@ -980,12 +1085,15 @@ test_that("relational count(g, a) order-enforcing", { test_that("relational count(b, g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "count" rel1 <- rel_from_df(con, df1, experimental = experimental) + "count" rel2 <- rel_aggregate( rel1, groups = list( @@ -1008,6 +1116,7 @@ test_that("relational count(b, g) order-enforcing", { } ) ) + "count" rel3 <- rel_order( rel2, list( @@ -1023,13 +1132,14 @@ test_that("relational count(b, g) order-enforcing", { } ) ) + "arrange" rel4 <- rel_order( rel3, list(expr_reference("b"), expr_reference("g"), expr_reference("n")) ) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(b = rep(2, 3L), g = 1:3, n = 1:3) ) @@ -1040,12 +1150,16 @@ test_that("relational count(b, g) order-enforcing", { test_that("relational distinct() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -1071,6 +1185,7 @@ test_that("relational distinct() order-preserving", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -1119,6 +1234,7 @@ test_that("relational distinct() order-preserving", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -1135,7 +1251,9 @@ test_that("relational distinct() order-preserving", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -1158,7 +1276,7 @@ test_that("relational distinct() order-preserving", { ) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -1167,12 +1285,16 @@ test_that("relational distinct() order-preserving", { test_that("relational distinct(a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -1198,6 +1320,7 @@ test_that("relational distinct(a) order-preserving", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -1226,6 +1349,7 @@ test_that("relational distinct(a) order-preserving", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -1242,7 +1366,9 @@ test_that("relational distinct(a) order-preserving", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -1255,7 +1381,7 @@ test_that("relational distinct(a) order-preserving", { ) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1)) ) @@ -1264,12 +1390,16 @@ test_that("relational distinct(a) order-preserving", { test_that("relational distinct(a, b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -1295,6 +1425,7 @@ test_that("relational distinct(a, b) order-preserving", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -1333,6 +1464,7 @@ test_that("relational distinct(a, b) order-preserving", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -1349,7 +1481,9 @@ test_that("relational distinct(a, b) order-preserving", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -1367,7 +1501,7 @@ test_that("relational distinct(a, b) order-preserving", { ) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -1376,12 +1510,16 @@ test_that("relational distinct(a, b) order-preserving", { test_that("relational distinct(b, b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -1407,6 +1545,7 @@ test_that("relational distinct(b, b) order-preserving", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -1435,6 +1574,7 @@ test_that("relational distinct(b, b) order-preserving", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -1451,7 +1591,9 @@ test_that("relational distinct(b, b) order-preserving", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -1464,7 +1606,7 @@ test_that("relational distinct(b, b) order-preserving", { ) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(b = 2) ) @@ -1473,12 +1615,16 @@ test_that("relational distinct(b, b) order-preserving", { test_that("relational distinct(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -1504,6 +1650,7 @@ test_that("relational distinct(g) order-preserving", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -1532,6 +1679,7 @@ test_that("relational distinct(g) order-preserving", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -1548,7 +1696,9 @@ test_that("relational distinct(g) order-preserving", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -1561,7 +1711,7 @@ test_that("relational distinct(g) order-preserving", { ) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -1570,15 +1720,20 @@ test_that("relational distinct(g) order-preserving", { test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 3, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -1613,6 +1768,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -1647,11 +1803,14 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -1672,6 +1831,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( } ) ) + "distinct" rel8 <- rel_project( rel7, list( @@ -1697,6 +1857,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -1725,6 +1886,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( } ) ) + "distinct" rel10 <- rel_filter( rel9, list( @@ -1741,7 +1903,9 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( ) ) ) + "distinct" rel11 <- rel_order(rel10, list(expr_reference("___row_number"))) + "distinct" rel12 <- rel_project( rel11, list( @@ -1754,7 +1918,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( ) rel12 out <- rel_to_altrep(rel12) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -1763,15 +1927,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 4, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -1806,6 +1975,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -1840,11 +2010,14 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -1865,6 +2038,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( } ) ) + "distinct" rel8 <- rel_project( rel7, list( @@ -1890,6 +2064,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -1918,6 +2093,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( } ) ) + "distinct" rel10 <- rel_filter( rel9, list( @@ -1934,7 +2110,9 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( ) ) ) + "distinct" rel11 <- rel_order(rel10, list(expr_reference("___row_number"))) + "distinct" rel12 <- rel_project( rel11, list( @@ -1947,7 +2125,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( ) rel12 out <- rel_to_altrep(rel12) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -1956,15 +2134,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 5, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -1999,6 +2182,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -2033,11 +2217,14 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -2058,6 +2245,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( } ) ) + "distinct" rel8 <- rel_project( rel7, list( @@ -2083,6 +2271,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -2111,6 +2300,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( } ) ) + "distinct" rel10 <- rel_filter( rel9, list( @@ -2127,7 +2317,9 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( ) ) ) + "distinct" rel11 <- rel_order(rel10, list(expr_reference("___row_number"))) + "distinct" rel12 <- rel_project( rel11, list( @@ -2140,7 +2332,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( ) rel12 out <- rel_to_altrep(rel12) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2149,15 +2341,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 6, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -2192,6 +2389,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -2226,11 +2424,14 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -2251,6 +2452,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( } ) ) + "distinct" rel8 <- rel_project( rel7, list( @@ -2276,6 +2478,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -2304,6 +2507,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( } ) ) + "distinct" rel10 <- rel_filter( rel9, list( @@ -2320,7 +2524,9 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( ) ) ) + "distinct" rel11 <- rel_order(rel10, list(expr_reference("___row_number"))) + "distinct" rel12 <- rel_project( rel11, list( @@ -2333,7 +2539,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( ) rel12 out <- rel_to_altrep(rel12) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2342,15 +2548,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 7, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -2385,6 +2596,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -2419,11 +2631,14 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -2444,6 +2659,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( } ) ) + "distinct" rel8 <- rel_project( rel7, list( @@ -2469,6 +2685,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -2497,6 +2714,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( } ) ) + "distinct" rel10 <- rel_filter( rel9, list( @@ -2513,7 +2731,9 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( ) ) ) + "distinct" rel11 <- rel_order(rel10, list(expr_reference("___row_number"))) + "distinct" rel12 <- rel_project( rel11, list( @@ -2526,7 +2746,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( ) rel12 out <- rel_to_altrep(rel12) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2535,12 +2755,16 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -2566,6 +2790,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -2604,6 +2829,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -2620,7 +2846,9 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -2643,7 +2871,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { ) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(a = c(1, 2, 4), b = rep(2, 3L), g = 1:3) ) @@ -2654,19 +2882,23 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { test_that("relational distinct() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_distinct(rel1) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -2675,11 +2907,14 @@ test_that("relational distinct() order-enforcing", { test_that("relational distinct(a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -2690,11 +2925,13 @@ test_that("relational distinct(a) order-enforcing", { } ) ) + "distinct" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1)) ) @@ -2703,11 +2940,14 @@ test_that("relational distinct(a) order-enforcing", { test_that("relational distinct(a, b) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -2723,11 +2963,13 @@ test_that("relational distinct(a, b) order-enforcing", { } ) ) + "distinct" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -2736,11 +2978,14 @@ test_that("relational distinct(a, b) order-enforcing", { test_that("relational distinct(b, b) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -2751,11 +2996,13 @@ test_that("relational distinct(b, b) order-enforcing", { } ) ) + "distinct" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("b"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(b = 2) ) @@ -2764,11 +3011,14 @@ test_that("relational distinct(b, b) order-enforcing", { test_that("relational distinct(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -2779,11 +3029,13 @@ test_that("relational distinct(g) order-enforcing", { } ) ) + "distinct" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("g"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2792,15 +3044,20 @@ test_that("relational distinct(g) order-enforcing", { test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 3, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "distinct" rel4 <- rel_project( rel3, list( @@ -2811,11 +3068,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( } ) ) + "distinct" rel5 <- rel_distinct(rel4) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("g"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2824,15 +3083,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 4, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "distinct" rel4 <- rel_project( rel3, list( @@ -2843,11 +3107,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( } ) ) + "distinct" rel5 <- rel_distinct(rel4) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("g"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2856,15 +3122,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 5, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "distinct" rel4 <- rel_project( rel3, list( @@ -2875,11 +3146,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( } ) ) + "distinct" rel5 <- rel_distinct(rel4) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("g"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2888,15 +3161,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 6, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "distinct" rel4 <- rel_project( rel3, list( @@ -2907,11 +3185,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( } ) ) + "distinct" rel5 <- rel_distinct(rel4) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("g"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2920,15 +3200,20 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 1L, b = 7, g = 2L) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "distinct" rel4 <- rel_project( rel3, list( @@ -2939,11 +3224,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( } ) ) + "distinct" rel5 <- rel_distinct(rel4) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("g"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(g = 1:3) ) @@ -2952,12 +3239,16 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "distinct" rel1 <- rel_from_df(con, df1, experimental = experimental) + "distinct" rel2 <- rel_project( rel1, list( @@ -2983,6 +3274,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { } ) ) + "distinct" rel3 <- rel_project( rel2, list( @@ -3021,6 +3313,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { } ) ) + "distinct" rel4 <- rel_filter( rel3, list( @@ -3037,7 +3330,9 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { ) ) ) + "distinct" rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) + "distinct" rel6 <- rel_project( rel5, list( @@ -3058,13 +3353,14 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { } ) ) + "arrange" rel7 <- rel_order( rel6, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel7 out <- rel_to_altrep(rel7) - expect_equal( + expect_identical( out, data.frame(a = c(1, 2, 4), b = rep(2, 3L), g = 1:3) ) @@ -3075,12 +3371,16 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { test_that("relational filter(a == 1) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_project( rel1, list( @@ -3106,6 +3406,7 @@ test_that("relational filter(a == 1) order-preserving", { } ) ) + "filter" rel3 <- rel_filter( rel2, list( @@ -3122,7 +3423,9 @@ test_that("relational filter(a == 1) order-preserving", { ) ) ) + "filter" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "filter" rel5 <- rel_project( rel4, list( @@ -3145,7 +3448,7 @@ test_that("relational filter(a == 1) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(a = 1, b = 2, g = 1L) ) @@ -3154,13 +3457,18 @@ test_that("relational filter(a == 1) order-preserving", { test_that("relational filter(a %in% 2:3, g == 2) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)')) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_project( rel1, list( @@ -3186,34 +3494,45 @@ test_that("relational filter(a %in% 2:3, g == 2) order-preserving", { } ) ) + "filter" rel3 <- rel_filter( rel2, list( expr_function( - "|", + "___coalesce", list( expr_function( - "==", + "|", list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2L, experimental = experimental) - } else { - expr_constant(2L) - }, - expr_reference("a") + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2L, experimental = experimental) + } else { + expr_constant(2L) + } + ) + ), + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(3L, experimental = experimental) + } else { + expr_constant(3L) + } + ) + ) ) ), - expr_function( - "==", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(3L, experimental = experimental) - } else { - expr_constant(3L) - }, - expr_reference("a") - ) - ) + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } ) ), expr_function( @@ -3229,7 +3548,9 @@ test_that("relational filter(a %in% 2:3, g == 2) order-preserving", { ) ) ) + "filter" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "filter" rel5 <- rel_project( rel4, list( @@ -3252,7 +3573,7 @@ test_that("relational filter(a %in% 2:3, g == 2) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L)) ) @@ -3261,14 +3582,19 @@ test_that("relational filter(a %in% 2:3, g == 2) order-preserving", { test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) invisible(dbExecute(con, 'CREATE MACRO "&"(x, y) AS (x AND y)')) + invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)')) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_project( rel1, list( @@ -3294,6 +3620,7 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { } ) ) + "filter" rel3 <- rel_filter( rel2, list( @@ -3301,30 +3628,40 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { "&", list( expr_function( - "|", + "___coalesce", list( expr_function( - "==", + "|", list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2L, experimental = experimental) - } else { - expr_constant(2L) - }, - expr_reference("a") + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2L, experimental = experimental) + } else { + expr_constant(2L) + } + ) + ), + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(3L, experimental = experimental) + } else { + expr_constant(3L) + } + ) + ) ) ), - expr_function( - "==", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(3L, experimental = experimental) - } else { - expr_constant(3L) - }, - expr_reference("a") - ) - ) + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } ) ), expr_function( @@ -3342,7 +3679,9 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { ) ) ) + "filter" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "filter" rel5 <- rel_project( rel4, list( @@ -3365,7 +3704,7 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L)) ) @@ -3374,13 +3713,17 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { test_that("relational filter(a != 2 | g != 2) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)')) - invisible(dbExecute(con, 'CREATE MACRO "!="(x, y) AS x <> y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "!="(x, y) AS "r_base::!="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_project( rel1, list( @@ -3406,6 +3749,7 @@ test_that("relational filter(a != 2 | g != 2) order-preserving", { } ) ) + "filter" rel3 <- rel_filter( rel2, list( @@ -3438,7 +3782,9 @@ test_that("relational filter(a != 2 | g != 2) order-preserving", { ) ) ) + "filter" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "filter" rel5 <- rel_project( rel4, list( @@ -3461,7 +3807,7 @@ test_that("relational filter(a != 2 | g != 2) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(a = c(1, 3, 4, 5, 6), b = rep(2, 5L), g = c(1L, 2L, 3L, 3L, 3L)) ) @@ -3472,12 +3818,16 @@ test_that("relational filter(a != 2 | g != 2) order-preserving", { test_that("relational filter(a == 1) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_filter( rel1, list( @@ -3494,13 +3844,14 @@ test_that("relational filter(a == 1) order-enforcing", { ) ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = 1, b = 2, g = 1L) ) @@ -3509,41 +3860,56 @@ test_that("relational filter(a == 1) order-enforcing", { test_that("relational filter(a %in% 2:3, g == 2) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)')) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_filter( rel1, list( expr_function( - "|", + "___coalesce", list( expr_function( - "==", + "|", list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2L, experimental = experimental) - } else { - expr_constant(2L) - }, - expr_reference("a") + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2L, experimental = experimental) + } else { + expr_constant(2L) + } + ) + ), + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(3L, experimental = experimental) + } else { + expr_constant(3L) + } + ) + ) ) ), - expr_function( - "==", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(3L, experimental = experimental) - } else { - expr_constant(3L) - }, - expr_reference("a") - ) - ) + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } ) ), expr_function( @@ -3559,13 +3925,14 @@ test_that("relational filter(a %in% 2:3, g == 2) order-enforcing", { ) ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L)) ) @@ -3574,14 +3941,19 @@ test_that("relational filter(a %in% 2:3, g == 2) order-enforcing", { test_that("relational filter(a %in% 2:3 & g == 2) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) invisible(dbExecute(con, 'CREATE MACRO "&"(x, y) AS (x AND y)')) + invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)')) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_filter( rel1, list( @@ -3589,30 +3961,40 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-enforcing", { "&", list( expr_function( - "|", + "___coalesce", list( expr_function( - "==", + "|", list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2L, experimental = experimental) - } else { - expr_constant(2L) - }, - expr_reference("a") + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2L, experimental = experimental) + } else { + expr_constant(2L) + } + ) + ), + expr_function( + "r_base::==", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(3L, experimental = experimental) + } else { + expr_constant(3L) + } + ) + ) ) ), - expr_function( - "==", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(3L, experimental = experimental) - } else { - expr_constant(3L) - }, - expr_reference("a") - ) - ) + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } ) ), expr_function( @@ -3630,13 +4012,14 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-enforcing", { ) ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L)) ) @@ -3645,13 +4028,17 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-enforcing", { test_that("relational filter(a != 2 | g != 2) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)')) - invisible(dbExecute(con, 'CREATE MACRO "!="(x, y) AS x <> y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "!="(x, y) AS "r_base::!="(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "filter" rel1 <- rel_from_df(con, df1, experimental = experimental) + "filter" rel2 <- rel_filter( rel1, list( @@ -3684,13 +4071,14 @@ test_that("relational filter(a != 2 | g != 2) order-enforcing", { ) ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = c(1, 3, 4, 5, 6), b = rep(2, 5L), g = c(1L, 2L, 3L, 3L, 3L)) ) @@ -3701,7 +4089,8 @@ test_that("relational filter(a != 2 | g != 2) order-enforcing", { test_that("relational full_join(join_by(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') @@ -3709,12 +4098,17 @@ test_that("relational full_join(join_by(a)) order-preserving", { invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "full_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "full_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "full_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "full_join" rel4 <- rel_set_alias(rel3, "rhs") + "full_join" rel5 <- rel_project( rel2, list( @@ -3730,6 +4124,7 @@ test_that("relational full_join(join_by(a)) order-preserving", { } ) ) + "full_join" rel6 <- rel_project( rel4, list( @@ -3745,6 +4140,7 @@ test_that("relational full_join(join_by(a)) order-preserving", { } ) ) + "full_join" rel7 <- rel_project( rel5, list( @@ -3765,6 +4161,7 @@ test_that("relational full_join(join_by(a)) order-preserving", { } ) ) + "full_join" rel8 <- rel_project( rel6, list( @@ -3785,6 +4182,7 @@ test_that("relational full_join(join_by(a)) order-preserving", { } ) ) + "full_join" rel9 <- rel_join( rel7, rel8, @@ -3793,10 +4191,12 @@ test_that("relational full_join(join_by(a)) order-preserving", { ), "outer" ) + "full_join" rel10 <- rel_order( rel9, list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8)) ) + "full_join" rel11 <- rel_project( rel10, list( @@ -3819,7 +4219,7 @@ test_that("relational full_join(join_by(a)) order-preserving", { ) rel11 out <- rel_to_altrep(rel11) - expect_equal( + expect_identical( out, data.frame(a = 1:5, b.x = rep(c(2, NA), c(4L, 1L)), b.y = rep(c(NA, 2), c(1L, 4L))) ) @@ -3830,7 +4230,8 @@ test_that("relational full_join(join_by(a)) order-preserving", { test_that("relational full_join(join_by(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') @@ -3838,12 +4239,17 @@ test_that("relational full_join(join_by(a)) order-enforcing", { invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "full_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "full_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "full_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "full_join" rel4 <- rel_set_alias(rel3, "rhs") + "full_join" rel5 <- rel_project( rel2, list( @@ -3859,6 +4265,7 @@ test_that("relational full_join(join_by(a)) order-enforcing", { } ) ) + "full_join" rel6 <- rel_project( rel4, list( @@ -3874,6 +4281,7 @@ test_that("relational full_join(join_by(a)) order-enforcing", { } ) ) + "full_join" rel7 <- rel_join( rel5, rel6, @@ -3882,6 +4290,7 @@ test_that("relational full_join(join_by(a)) order-enforcing", { ), "outer" ) + "full_join" rel8 <- rel_project( rel7, list( @@ -3902,13 +4311,14 @@ test_that("relational full_join(join_by(a)) order-enforcing", { } ) ) + "arrange" rel9 <- rel_order( rel8, list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y")) ) rel9 out <- rel_to_altrep(rel9) - expect_equal( + expect_identical( out, data.frame(a = 1:5, b.x = rep(c(2, NA), c(4L, 1L)), b.y = rep(c(NA, 2), c(1L, 4L))) ) @@ -3919,7 +4329,8 @@ test_that("relational full_join(join_by(a)) order-enforcing", { test_that("relational inner_join(join_by(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') @@ -3927,12 +4338,17 @@ test_that("relational inner_join(join_by(a)) order-preserving", { invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "inner_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "inner_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "inner_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "inner_join" rel4 <- rel_set_alias(rel3, "rhs") + "inner_join" rel5 <- rel_project( rel2, list( @@ -3948,6 +4364,7 @@ test_that("relational inner_join(join_by(a)) order-preserving", { } ) ) + "inner_join" rel6 <- rel_project( rel4, list( @@ -3963,6 +4380,7 @@ test_that("relational inner_join(join_by(a)) order-preserving", { } ) ) + "inner_join" rel7 <- rel_project( rel5, list( @@ -3983,6 +4401,7 @@ test_that("relational inner_join(join_by(a)) order-preserving", { } ) ) + "inner_join" rel8 <- rel_project( rel6, list( @@ -4003,6 +4422,7 @@ test_that("relational inner_join(join_by(a)) order-preserving", { } ) ) + "inner_join" rel9 <- rel_join( rel7, rel8, @@ -4011,10 +4431,12 @@ test_that("relational inner_join(join_by(a)) order-preserving", { ), "inner" ) + "inner_join" rel10 <- rel_order( rel9, list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8)) ) + "inner_join" rel11 <- rel_project( rel10, list( @@ -4037,7 +4459,7 @@ test_that("relational inner_join(join_by(a)) order-preserving", { ) rel11 out <- rel_to_altrep(rel11) - expect_equal( + expect_identical( out, data.frame(a = 2:4, b.x = rep(2, 3L), b.y = rep(2, 3L)) ) @@ -4048,7 +4470,8 @@ test_that("relational inner_join(join_by(a)) order-preserving", { test_that("relational inner_join(join_by(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') @@ -4056,12 +4479,17 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "inner_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "inner_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "inner_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "inner_join" rel4 <- rel_set_alias(rel3, "rhs") + "inner_join" rel5 <- rel_project( rel2, list( @@ -4077,6 +4505,7 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { } ) ) + "inner_join" rel6 <- rel_project( rel4, list( @@ -4092,6 +4521,7 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { } ) ) + "inner_join" rel7 <- rel_join( rel5, rel6, @@ -4100,6 +4530,7 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { ), "inner" ) + "inner_join" rel8 <- rel_project( rel7, list( @@ -4120,13 +4551,14 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { } ) ) + "arrange" rel9 <- rel_order( rel8, list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y")) ) rel9 out <- rel_to_altrep(rel9) - expect_equal( + expect_identical( out, data.frame(a = 2:4, b.x = rep(2, 3L), b.y = rep(2, 3L)) ) @@ -4137,20 +4569,27 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { test_that("relational intersect() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "semi_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "semi_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "semi_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "semi_join" rel4 <- rel_set_alias(rel3, "rhs") + "semi_join" rel5 <- rel_project( rel2, list( @@ -4171,6 +4610,7 @@ test_that("relational intersect() order-preserving", { } ) ) + "semi_join" rel6 <- rel_join( rel5, rel4, @@ -4180,7 +4620,9 @@ test_that("relational intersect() order-preserving", { ), "semi" ) + "semi_join" rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5))) + "semi_join" rel8 <- rel_project( rel7, list( @@ -4196,6 +4638,7 @@ test_that("relational intersect() order-preserving", { } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -4216,6 +4659,7 @@ test_that("relational intersect() order-preserving", { } ) ) + "distinct" rel10 <- rel_project( rel9, list( @@ -4254,6 +4698,7 @@ test_that("relational intersect() order-preserving", { } ) ) + "distinct" rel11 <- rel_filter( rel10, list( @@ -4270,7 +4715,9 @@ test_that("relational intersect() order-preserving", { ) ) ) + "distinct" rel12 <- rel_order(rel11, list(expr_reference("___row_number"))) + "distinct" rel13 <- rel_project( rel12, list( @@ -4288,7 +4735,7 @@ test_that("relational intersect() order-preserving", { ) rel13 out <- rel_to_altrep(rel13) - expect_equal( + expect_identical( out, data.frame(a = 2:4, b = rep(2, 3L)) ) @@ -4299,19 +4746,24 @@ test_that("relational intersect() order-preserving", { test_that("relational intersect() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "intersect" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "intersect" rel2 <- rel_from_df(con, df2, experimental = experimental) + "intersect" rel3 <- rel_set_intersect(rel1, rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = 2:4, b = rep(2, 3L)) ) @@ -4322,7 +4774,8 @@ test_that("relational intersect() order-enforcing", { test_that("relational left_join(join_by(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') @@ -4330,12 +4783,17 @@ test_that("relational left_join(join_by(a)) order-preserving", { invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "left_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "left_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "left_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "left_join" rel4 <- rel_set_alias(rel3, "rhs") + "left_join" rel5 <- rel_project( rel2, list( @@ -4351,6 +4809,7 @@ test_that("relational left_join(join_by(a)) order-preserving", { } ) ) + "left_join" rel6 <- rel_project( rel4, list( @@ -4366,6 +4825,7 @@ test_that("relational left_join(join_by(a)) order-preserving", { } ) ) + "left_join" rel7 <- rel_project( rel5, list( @@ -4386,6 +4846,7 @@ test_that("relational left_join(join_by(a)) order-preserving", { } ) ) + "left_join" rel8 <- rel_project( rel6, list( @@ -4406,6 +4867,7 @@ test_that("relational left_join(join_by(a)) order-preserving", { } ) ) + "left_join" rel9 <- rel_join( rel7, rel8, @@ -4414,10 +4876,12 @@ test_that("relational left_join(join_by(a)) order-preserving", { ), "left" ) + "left_join" rel10 <- rel_order( rel9, list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8)) ) + "left_join" rel11 <- rel_project( rel10, list( @@ -4440,7 +4904,7 @@ test_that("relational left_join(join_by(a)) order-preserving", { ) rel11 out <- rel_to_altrep(rel11) - expect_equal( + expect_identical( out, data.frame(a = 1:4, b.x = rep(2, 4L), b.y = c(NA, 2, 2, 2)) ) @@ -4451,7 +4915,8 @@ test_that("relational left_join(join_by(a)) order-preserving", { test_that("relational left_join(join_by(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') @@ -4459,12 +4924,17 @@ test_that("relational left_join(join_by(a)) order-enforcing", { invisible(dbExecute(con, 'CREATE MACRO "___coalesce"(x, y) AS COALESCE(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "left_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "left_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "left_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "left_join" rel4 <- rel_set_alias(rel3, "rhs") + "left_join" rel5 <- rel_project( rel2, list( @@ -4480,6 +4950,7 @@ test_that("relational left_join(join_by(a)) order-enforcing", { } ) ) + "left_join" rel6 <- rel_project( rel4, list( @@ -4495,6 +4966,7 @@ test_that("relational left_join(join_by(a)) order-enforcing", { } ) ) + "left_join" rel7 <- rel_join( rel5, rel6, @@ -4503,6 +4975,7 @@ test_that("relational left_join(join_by(a)) order-enforcing", { ), "left" ) + "left_join" rel8 <- rel_project( rel7, list( @@ -4523,13 +4996,14 @@ test_that("relational left_join(join_by(a)) order-enforcing", { } ) ) + "arrange" rel9 <- rel_order( rel8, list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y")) ) rel9 out <- rel_to_altrep(rel9) - expect_equal( + expect_identical( out, data.frame(a = 1:4, b.x = rep(2, 4L), b.y = c(NA, 2, 2, 2)) ) @@ -4540,14 +5014,16 @@ test_that("relational left_join(join_by(a)) order-enforcing", { test_that("relational mutate() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) rel1 out <- rel_to_altrep(rel1) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -4556,11 +5032,14 @@ test_that("relational mutate() order-preserving", { test_that("relational mutate(a + 1) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -4598,7 +5077,7 @@ test_that("relational mutate(a + 1) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -4613,11 +5092,14 @@ test_that("relational mutate(a + 1) order-preserving", { test_that("relational mutate(a + 1, .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -4643,6 +5125,7 @@ test_that("relational mutate(a + 1, .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -4683,7 +5166,9 @@ test_that("relational mutate(a + 1, .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -4711,7 +5196,7 @@ test_that("relational mutate(a + 1, .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -4726,11 +5211,14 @@ test_that("relational mutate(a + 1, .by = g) order-preserving", { test_that("relational mutate(c = a + 1) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -4768,7 +5256,7 @@ test_that("relational mutate(c = a + 1) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -4782,11 +5270,14 @@ test_that("relational mutate(c = a + 1) order-preserving", { test_that("relational mutate(`if` = a + 1) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -4824,7 +5315,7 @@ test_that("relational mutate(`if` = a + 1) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -4839,11 +5330,14 @@ test_that("relational mutate(`if` = a + 1) order-preserving", { test_that("relational mutate(sum(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -4871,7 +5365,7 @@ test_that("relational mutate(sum(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -4886,11 +5380,14 @@ test_that("relational mutate(sum(a)) order-preserving", { test_that("relational mutate(sum(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -4916,6 +5413,7 @@ test_that("relational mutate(sum(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -4946,7 +5444,9 @@ test_that("relational mutate(sum(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -4974,7 +5474,7 @@ test_that("relational mutate(sum(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -4989,11 +5489,14 @@ test_that("relational mutate(sum(a), .by = g) order-preserving", { test_that("relational mutate(mean(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5021,7 +5524,7 @@ test_that("relational mutate(mean(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5036,11 +5539,14 @@ test_that("relational mutate(mean(a)) order-preserving", { test_that("relational mutate(mean(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5066,6 +5572,7 @@ test_that("relational mutate(mean(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -5096,7 +5603,9 @@ test_that("relational mutate(mean(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -5124,7 +5633,7 @@ test_that("relational mutate(mean(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5139,11 +5648,14 @@ test_that("relational mutate(mean(a), .by = g) order-preserving", { test_that("relational mutate(sd(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5171,7 +5683,7 @@ test_that("relational mutate(sd(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5186,11 +5698,14 @@ test_that("relational mutate(sd(a)) order-preserving", { test_that("relational mutate(sd(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5216,6 +5731,7 @@ test_that("relational mutate(sd(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -5246,7 +5762,9 @@ test_that("relational mutate(sd(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -5274,7 +5792,7 @@ test_that("relational mutate(sd(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5289,11 +5807,14 @@ test_that("relational mutate(sd(a), .by = g) order-preserving", { test_that("relational mutate(lag(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5331,7 +5852,7 @@ test_that("relational mutate(lag(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5346,11 +5867,14 @@ test_that("relational mutate(lag(a)) order-preserving", { test_that("relational mutate(lag(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5376,6 +5900,7 @@ test_that("relational mutate(lag(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -5416,7 +5941,9 @@ test_that("relational mutate(lag(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -5444,7 +5971,7 @@ test_that("relational mutate(lag(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5459,11 +5986,14 @@ test_that("relational mutate(lag(a), .by = g) order-preserving", { test_that("relational mutate(lead(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5501,7 +6031,7 @@ test_that("relational mutate(lead(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5516,11 +6046,14 @@ test_that("relational mutate(lead(a)) order-preserving", { test_that("relational mutate(lead(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5546,6 +6079,7 @@ test_that("relational mutate(lead(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -5586,7 +6120,9 @@ test_that("relational mutate(lead(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -5614,7 +6150,7 @@ test_that("relational mutate(lead(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5629,11 +6165,14 @@ test_that("relational mutate(lead(a), .by = g) order-preserving", { test_that("relational mutate(lag(a, 2)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5671,7 +6210,7 @@ test_that("relational mutate(lag(a, 2)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5686,11 +6225,14 @@ test_that("relational mutate(lag(a, 2)) order-preserving", { test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5716,6 +6258,7 @@ test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -5756,7 +6299,9 @@ test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -5784,7 +6329,7 @@ test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5799,11 +6344,14 @@ test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { test_that("relational mutate(lead(a, 2)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5841,7 +6389,7 @@ test_that("relational mutate(lead(a, 2)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5856,11 +6404,14 @@ test_that("relational mutate(lead(a, 2)) order-preserving", { test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -5886,6 +6437,7 @@ test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -5926,7 +6478,9 @@ test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -5954,7 +6508,7 @@ test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -5969,11 +6523,14 @@ test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { test_that("relational mutate(lag(a, 4)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6011,7 +6568,7 @@ test_that("relational mutate(lag(a, 4)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6026,11 +6583,14 @@ test_that("relational mutate(lag(a, 4)) order-preserving", { test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6056,6 +6616,7 @@ test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -6096,7 +6657,9 @@ test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -6124,7 +6687,7 @@ test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6139,11 +6702,14 @@ test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { test_that("relational mutate(lead(a, 4)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6181,7 +6747,7 @@ test_that("relational mutate(lead(a, 4)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6196,11 +6762,14 @@ test_that("relational mutate(lead(a, 4)) order-preserving", { test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6226,6 +6795,7 @@ test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -6266,7 +6836,9 @@ test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -6294,7 +6866,7 @@ test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6309,11 +6881,14 @@ test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { test_that("relational mutate(lag(a, default = 0)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6355,7 +6930,7 @@ test_that("relational mutate(lag(a, default = 0)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6370,11 +6945,14 @@ test_that("relational mutate(lag(a, default = 0)) order-preserving", { test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6400,6 +6978,7 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -6444,7 +7023,9 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -6472,7 +7053,7 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6487,11 +7068,14 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { test_that("relational mutate(lead(a, default = 1000)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6533,7 +7117,7 @@ test_that("relational mutate(lead(a, default = 1000)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6548,11 +7132,14 @@ test_that("relational mutate(lead(a, default = 1000)) order-preserving", { test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6578,6 +7165,7 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving" } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -6622,7 +7210,9 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving" } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -6650,7 +7240,7 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving" ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6665,11 +7255,14 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving" test_that("relational mutate(min(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6697,7 +7290,7 @@ test_that("relational mutate(min(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6712,11 +7305,14 @@ test_that("relational mutate(min(a)) order-preserving", { test_that("relational mutate(min(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6742,6 +7338,7 @@ test_that("relational mutate(min(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -6772,7 +7369,9 @@ test_that("relational mutate(min(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -6800,7 +7399,7 @@ test_that("relational mutate(min(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6815,11 +7414,14 @@ test_that("relational mutate(min(a), .by = g) order-preserving", { test_that("relational mutate(max(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6847,7 +7449,7 @@ test_that("relational mutate(max(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6862,11 +7464,14 @@ test_that("relational mutate(max(a)) order-preserving", { test_that("relational mutate(max(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6892,6 +7497,7 @@ test_that("relational mutate(max(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -6922,7 +7528,9 @@ test_that("relational mutate(max(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -6950,7 +7558,7 @@ test_that("relational mutate(max(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -6965,11 +7573,14 @@ test_that("relational mutate(max(a), .by = g) order-preserving", { test_that("relational mutate(first(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -6997,7 +7608,7 @@ test_that("relational mutate(first(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7012,11 +7623,14 @@ test_that("relational mutate(first(a)) order-preserving", { test_that("relational mutate(first(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7042,6 +7656,7 @@ test_that("relational mutate(first(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -7072,7 +7687,9 @@ test_that("relational mutate(first(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -7100,7 +7717,7 @@ test_that("relational mutate(first(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7115,11 +7732,14 @@ test_that("relational mutate(first(a), .by = g) order-preserving", { test_that("relational mutate(last(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7147,7 +7767,7 @@ test_that("relational mutate(last(a)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7162,11 +7782,14 @@ test_that("relational mutate(last(a)) order-preserving", { test_that("relational mutate(last(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7192,6 +7815,7 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -7222,7 +7846,9 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -7250,7 +7876,7 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7265,11 +7891,14 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { test_that("relational mutate(nth(a, 2)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7313,7 +7942,7 @@ test_that("relational mutate(nth(a, 2)) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7328,11 +7957,14 @@ test_that("relational mutate(nth(a, 2)) order-preserving", { test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7358,6 +7990,7 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -7404,7 +8037,9 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { } ) ) + "mutate" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" rel5 <- rel_project( rel4, list( @@ -7432,7 +8067,7 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7447,7 +8082,8 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { test_that("relational mutate(a / b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -7457,7 +8093,9 @@ test_that("relational mutate(a / b) order-preserving", { ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7485,7 +8123,7 @@ test_that("relational mutate(a / b) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7500,7 +8138,8 @@ test_that("relational mutate(a / b) order-preserving", { test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -7510,7 +8149,9 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-pres ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7540,6 +8181,7 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-pres } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -7580,6 +8222,7 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-pres } ) ) + "mutate" rel4 <- rel_project( rel3, list( @@ -7625,6 +8268,7 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-pres } ) ) + "mutate" rel5 <- rel_project( rel4, list( @@ -7677,7 +8321,7 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-pres ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7693,7 +8337,8 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-pres test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log(d))) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -7704,7 +8349,9 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log invisible(dbExecute(con, 'CREATE MACRO "suppressWarnings"(x) AS (x)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7734,6 +8381,7 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -7773,6 +8421,7 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log } ) ) + "mutate" rel4 <- rel_project( rel3, list( @@ -7808,6 +8457,7 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log } ) ) + "mutate" rel5 <- rel_project( rel4, list( @@ -7850,7 +8500,7 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -7867,7 +8517,8 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(log10(d))) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -7878,7 +8529,9 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l invisible(dbExecute(con, 'CREATE MACRO "suppressWarnings"(x) AS (x)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -7908,6 +8561,7 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -7947,6 +8601,7 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l } ) ) + "mutate" rel4 <- rel_project( rel3, list( @@ -7982,6 +8637,7 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l } ) ) + "mutate" rel5 <- rel_project( rel4, list( @@ -8024,7 +8680,7 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -8041,7 +8697,8 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l test_that("relational mutate(c = 10, d = log(c)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -8051,7 +8708,9 @@ test_that("relational mutate(c = 10, d = log(c)) order-preserving", { ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8081,6 +8740,7 @@ test_that("relational mutate(c = 10, d = log(c)) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -8113,7 +8773,7 @@ test_that("relational mutate(c = 10, d = log(c)) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -8128,7 +8788,8 @@ test_that("relational mutate(c = 10, d = log(c)) order-preserving", { test_that("relational mutate(c = 10, d = log10(c)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -8138,7 +8799,9 @@ test_that("relational mutate(c = 10, d = log10(c)) order-preserving", { ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8168,6 +8831,7 @@ test_that("relational mutate(c = 10, d = log10(c)) order-preserving", { } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -8200,7 +8864,7 @@ test_that("relational mutate(c = 10, d = log10(c)) order-preserving", { ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -8214,10 +8878,9 @@ test_that("relational mutate(c = 10, d = log10(c)) order-preserving", { }) test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-preserving", { - skip_if_not(TEST_RE2) - # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( @@ -8227,7 +8890,9 @@ test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-preserv ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8257,6 +8922,7 @@ test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-preserv } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -8299,7 +8965,7 @@ test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-preserv ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), @@ -8312,13 +8978,17 @@ test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-preserv dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = .data$b) order-preserving", { +test_that("relational mutate(d = a %in% NA_real_) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "is.na"(x) AS (x IS NULL OR isnan(x))')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8338,55 +9008,36 @@ test_that("relational mutate(c = .data$b) order-preserving", { tmp_expr }, { - tmp_expr <- expr_reference("b") - expr_set_alias(tmp_expr, "c") + tmp_expr <- expr_function("is.na", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = rep(2, 6L) + d = logical(6) ) ) dbDisconnect(con, shutdown = TRUE) }) -# mutate order-enforcing --------------------------------------------------------------- - -test_that("relational mutate() order-enforcing", { - # Autogenerated - con <- dbConnect(duckdb()) - experimental <- FALSE - df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) - - rel1 <- rel_from_df(con, df1, experimental = experimental) - rel2 <- rel_order( - rel1, - list(expr_reference("a"), expr_reference("b"), expr_reference("g")) - ) - rel2 - out <- rel_to_altrep(rel2) - expect_equal( - out, - data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) - ) - dbDisconnect(con, shutdown = TRUE) -}) - -test_that("relational mutate(a + 1) order-enforcing", { +test_that("relational mutate(d = a %in% NULL) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8406,48 +9057,40 @@ test_that("relational mutate(a + 1) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_function( - "+", - list( - expr_reference("a"), - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - } - ) - ) - expr_set_alias(tmp_expr, "a + 1") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("a + 1")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a + 1` = seq(2, 7, by = 1), - check.names = FALSE + d = logical(6) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(a + 1, .by = g) order-enforcing", { +test_that("relational mutate(d = a %in% integer()) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8467,48 +9110,41 @@ test_that("relational mutate(a + 1, .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_function( - "+", - list( - expr_reference("a"), - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - } - ) - ) - expr_set_alias(tmp_expr, "a + 1") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("a + 1")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a + 1` = seq(2, 7, by = 1), - check.names = FALSE + d = logical(6) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = a + 1) order-enforcing", { +test_that("relational mutate(d = NA_real_, e = is.na(d)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "is.na"(x) AS (x IS NULL OR isnan(x))')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8528,49 +9164,19 @@ test_that("relational mutate(c = a + 1) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_function( - "+", - list( - expr_reference("a"), - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - } - ) - ) - expr_set_alias(tmp_expr, "c") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA_real_, experimental = experimental) + } else { + expr_constant(NA_real_) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( + "mutate" + rel3 <- rel_project( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( - out, - data.frame( - a = seq(1, 6, by = 1), - b = rep(2, 6L), - g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = seq(2, 7, by = 1) - ) - ) - dbDisconnect(con, shutdown = TRUE) -}) - -test_that("relational mutate(`if` = a + 1) order-enforcing", { - # Autogenerated - con <- dbConnect(duckdb()) - experimental <- FALSE - df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) - - rel1 <- rel_from_df(con, df1, experimental = experimental) - rel2 <- rel_project( - rel1, list( { tmp_expr <- expr_reference("a") @@ -8588,48 +9194,43 @@ test_that("relational mutate(`if` = a + 1) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_function( - "+", - list( - expr_reference("a"), - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - } - ) - ) - expr_set_alias(tmp_expr, "if") + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_function("is.na", list(expr_reference("d"))) + expr_set_alias(tmp_expr, "e") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("if")) - ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `if` = seq(2, 7, by = 1), - check.names = FALSE + d = rep(NA_real_, 6L), + e = rep(TRUE, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(sum(a)) order-enforcing", { +test_that("relational mutate(d = NaN, e = is.na(d)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "is.na"(x) AS (x IS NULL OR isnan(x))')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8649,40 +9250,19 @@ test_that("relational mutate(sum(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("sum", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "sum(a)") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NaN, experimental = experimental) + } else { + expr_constant(NaN) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( + "mutate" + rel3 <- rel_project( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sum(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( - out, - data.frame( - a = seq(1, 6, by = 1), - b = rep(2, 6L), - g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sum(a)` = rep(21, 6L), - check.names = FALSE - ) - ) - dbDisconnect(con, shutdown = TRUE) -}) - -test_that("relational mutate(sum(a), .by = g) order-enforcing", { - # Autogenerated - con <- dbConnect(duckdb()) - experimental <- FALSE - df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) - - rel1 <- rel_from_df(con, df1, experimental = experimental) - rel2 <- rel_project( - rel1, list( { tmp_expr <- expr_reference("a") @@ -8700,38 +9280,43 @@ test_that("relational mutate(sum(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("sum", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "sum(a)") + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_function("is.na", list(expr_reference("d"))) + expr_set_alias(tmp_expr, "e") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sum(a)")) - ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sum(a)` = c(1, 5, 5, 15, 15, 15), - check.names = FALSE + d = rep(NaN, 6L), + e = rep(TRUE, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(mean(a)) order-enforcing", { +test_that("relational mutate(d = row_number()) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8751,38 +9336,37 @@ test_that("relational mutate(mean(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("mean", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "mean(a)") + tmp_expr <- expr_function( + "r_base::as.integer", + list( + expr_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL) + ) + ) + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("mean(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, - data.frame( - a = seq(1, 6, by = 1), - b = rep(2, 6L), - g = c(1L, 2L, 2L, 3L, 3L, 3L), - `mean(a)` = rep(3.5, 6L), - check.names = FALSE - ) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), d = 1:6) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(mean(a), .by = g) order-enforcing", { +test_that("relational mutate(d = row_number(), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8802,40 +9386,15 @@ test_that("relational mutate(mean(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("mean", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "mean(a)") + tmp_expr <- expr_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "___row_number") tmp_expr } ) ) - rel3 <- rel_order( + "mutate" + rel3 <- rel_project( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("mean(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( - out, - data.frame( - a = seq(1, 6, by = 1), - b = rep(2, 6L), - g = c(1L, 2L, 2L, 3L, 3L, 3L), - `mean(a)` = c(1, 2.5, 2.5, 5, 5, 5), - check.names = FALSE - ) - ) - dbDisconnect(con, shutdown = TRUE) -}) - -test_that("relational mutate(sd(a)) order-enforcing", { - # Autogenerated - con <- dbConnect(duckdb()) - experimental <- FALSE - df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) - - rel1 <- rel_from_df(con, df1, experimental = experimental) - rel2 <- rel_project( - rel1, list( { tmp_expr <- expr_reference("a") @@ -8853,40 +9412,27 @@ test_that("relational mutate(sd(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("stddev", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "sd(a)") + tmp_expr <- expr_reference("___row_number") + expr_set_alias(tmp_expr, "___row_number") + tmp_expr + }, + { + tmp_expr <- expr_function( + "r_base::as.integer", + list( + expr_window(expr_function("row_number", list()), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + ) + ) + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sd(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( - out, - data.frame( - a = seq(1, 6, by = 1), - b = rep(2, 6L), - g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sd(a)` = rep(0x1.deeea11683f49p+0, 6L), - check.names = FALSE - ) - ) - dbDisconnect(con, shutdown = TRUE) -}) - -test_that("relational mutate(sd(a), .by = g) order-enforcing", { - # Autogenerated - con <- dbConnect(duckdb()) - experimental <- FALSE - df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) - - rel1 <- rel_from_df(con, df1, experimental = experimental) - rel2 <- rel_project( - rel1, + "mutate" + rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "mutate" + rel5 <- rel_project( + rel4, list( { tmp_expr <- expr_reference("a") @@ -8904,38 +9450,36 @@ test_that("relational mutate(sd(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("stddev", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "sd(a)") + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sd(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel5 + out <- rel_to_altrep(rel5) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sd(a)` = c(NA, 0.7071067811865476, 0.7071067811865476, 1, 1, 1), - check.names = FALSE + d = c(1L, 1L, 2L, 1L, 2L, 3L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a)) order-enforcing", { +test_that("relational mutate(c = .data$b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -8955,48 +9499,37 @@ test_that("relational mutate(lag(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lag(a)") + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "c") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a)` = c(NA, 1, 2, 3, 4, 5), - check.names = FALSE + c = rep(2, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a), .by = g) order-enforcing", { +test_that("relational mutate(d = NA) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "___null"() AS CAST(NULL AS BOOLEAN)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9016,48 +9549,36 @@ test_that("relational mutate(lag(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lag(a)") + tmp_expr <- expr_function("___null", list()) + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a)` = c(NA, NA, 2, NA, 4, 5), - check.names = FALSE + d = rep(NA, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a)) order-enforcing", { +test_that("relational mutate(d = NA_integer_) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9077,48 +9598,40 @@ test_that("relational mutate(lead(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lead(a)") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA_integer_, experimental = experimental) + } else { + expr_constant(NA_integer_) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a)` = c(2, 3, 4, 5, 6, NA), - check.names = FALSE + d = rep(NA_integer_, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a), .by = g) order-enforcing", { +test_that("relational mutate(d = NA_real_) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9138,48 +9651,40 @@ test_that("relational mutate(lead(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lead(a)") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA_real_, experimental = experimental) + } else { + expr_constant(NA_real_) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a)` = c(NA, 3, NA, 5, 6, NA), - check.names = FALSE + d = rep(NA_real_, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a, 2)) order-enforcing", { +test_that("relational mutate(d = NA_character_) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9199,48 +9704,48 @@ test_that("relational mutate(lag(a, 2)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2, experimental = experimental) - } else { - expr_constant(2) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lag(a, 2)") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA_character_, experimental = experimental) + } else { + expr_constant(NA_character_) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 2)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 2)` = c(NA, NA, 1, 2, 3, 4), - check.names = FALSE + d = rep(NA_character_, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a, 2), .by = g) order-enforcing", { +test_that("relational mutate(d = if_else(a > 1, \"ok\", NA)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible( + dbExecute( + con, + 'CREATE MACRO "if_else"(test, yes, no) AS (CASE WHEN test THEN yes ELSE no END)' + ) + ) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO ">"(x, y) AS "r_base::>"(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9260,48 +9765,86 @@ test_that("relational mutate(lag(a, 2), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2, experimental = experimental) - } else { - expr_constant(2) - }, - default_expr = NULL + tmp_expr <- expr_function( + "if_else", + list( + expr_function( + ">", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) + ), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant("ok", experimental = experimental) + } else { + expr_constant("ok") + }, + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA, experimental = experimental) + } else { + expr_constant(NA) + } + ) ) - expr_set_alias(tmp_expr, "lag(a, 2)") + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_order( - rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 2)")) - ) - rel3 - out <- rel_to_altrep(rel3) - expect_equal( + rel2 + out <- rel_to_altrep(rel2) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 2)` = rep(c(NA, 4), c(5L, 1L)), - check.names = FALSE + d = rep(c(NA, "ok"), c(1L, 5L)) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a, 2)) order-enforcing", { +# mutate order-enforcing --------------------------------------------------------------- + +test_that("relational mutate() order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "arrange" + rel2 <- rel_order( + rel1, + list(expr_reference("a"), expr_reference("b"), expr_reference("g")) + ) + rel2 + out <- rel_to_altrep(rel2) + expect_identical( + out, + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(a + 1) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9321,48 +9864,52 @@ test_that("relational mutate(lead(a, 2)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2, experimental = experimental) - } else { - expr_constant(2) - }, - default_expr = NULL + tmp_expr <- expr_function( + "+", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) ) - expr_set_alias(tmp_expr, "lead(a, 2)") + expr_set_alias(tmp_expr, "a + 1") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 2)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("a + 1")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, 2)` = c(3, 4, 5, 6, NA, NA), + `a + 1` = seq(2, 7, by = 1), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a, 2), .by = g) order-enforcing", { +test_that("relational mutate(a + 1, .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9382,48 +9929,52 @@ test_that("relational mutate(lead(a, 2), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2, experimental = experimental) - } else { - expr_constant(2) - }, - default_expr = NULL + tmp_expr <- expr_function( + "+", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) ) - expr_set_alias(tmp_expr, "lead(a, 2)") + expr_set_alias(tmp_expr, "a + 1") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 2)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("a + 1")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, 2)` = c(NA, NA, NA, 6, NA, NA), + `a + 1` = seq(2, 7, by = 1), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a, 4)) order-enforcing", { +test_that("relational mutate(c = a + 1) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9443,48 +9994,51 @@ test_that("relational mutate(lag(a, 4)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(4, experimental = experimental) - } else { - expr_constant(4) - }, - default_expr = NULL + tmp_expr <- expr_function( + "+", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) ) - expr_set_alias(tmp_expr, "lag(a, 4)") + expr_set_alias(tmp_expr, "c") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 4)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 4)` = c(NA, NA, NA, NA, 1, 2), - check.names = FALSE + c = seq(2, 7, by = 1) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a, 4), .by = g) order-enforcing", { +test_that("relational mutate(`if` = a + 1) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9504,48 +10058,52 @@ test_that("relational mutate(lag(a, 4), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(4, experimental = experimental) - } else { - expr_constant(4) - }, - default_expr = NULL + tmp_expr <- expr_function( + "+", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) ) - expr_set_alias(tmp_expr, "lag(a, 4)") + expr_set_alias(tmp_expr, "if") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 4)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("if")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 4)` = rep(NA_real_, 6L), + `if` = seq(2, 7, by = 1), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a, 4)) order-enforcing", { +test_that("relational mutate(sum(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9565,48 +10123,42 @@ test_that("relational mutate(lead(a, 4)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(4, experimental = experimental) - } else { - expr_constant(4) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lead(a, 4)") + tmp_expr <- expr_window(expr_function("sum", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "sum(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 4)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sum(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, 4)` = c(5, 6, NA, NA, NA, NA), + `sum(a)` = rep(21, 6L), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a, 4), .by = g) order-enforcing", { +test_that("relational mutate(sum(a), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9626,48 +10178,42 @@ test_that("relational mutate(lead(a, 4), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(4, experimental = experimental) - } else { - expr_constant(4) - }, - default_expr = NULL - ) - expr_set_alias(tmp_expr, "lead(a, 4)") + tmp_expr <- expr_window(expr_function("sum", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "sum(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 4)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sum(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, 4)` = rep(NA_real_, 6L), + `sum(a)` = c(1, 5, 5, 15, 15, 15), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a, default = 0)) order-enforcing", { +test_that("relational mutate(mean(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9687,52 +10233,42 @@ test_that("relational mutate(lag(a, default = 0)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(0, experimental = experimental) - } else { - expr_constant(0) - } - ) - expr_set_alias(tmp_expr, "lag(a, default = 0)") + tmp_expr <- expr_window(expr_function("mean", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "mean(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, default = 0)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("mean(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, default = 0)` = seq(0, 5, by = 1), + `mean(a)` = rep(3.5, 6L), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lag(a, default = 0), .by = g) order-enforcing", { +test_that("relational mutate(mean(a), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9752,52 +10288,42 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lag", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(0, experimental = experimental) - } else { - expr_constant(0) - } - ) - expr_set_alias(tmp_expr, "lag(a, default = 0)") + tmp_expr <- expr_window(expr_function("mean", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "mean(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, default = 0)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("mean(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, default = 0)` = c(0, 0, 2, 0, 4, 5), + `mean(a)` = c(1, 2.5, 2.5, 5, 5, 5), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a, default = 1000)) order-enforcing", { +test_that("relational mutate(sd(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9817,52 +10343,42 @@ test_that("relational mutate(lead(a, default = 1000)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1000, experimental = experimental) - } else { - expr_constant(1000) - } - ) - expr_set_alias(tmp_expr, "lead(a, default = 1000)") + tmp_expr <- expr_window(expr_function("stddev", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "sd(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, default = 1000)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sd(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, default = 1000)` = c(2, 3, 4, 5, 6, 1000), + `sd(a)` = rep(0x1.deeea11683f49p+0, 6L), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(lead(a, default = 1000), .by = g) order-enforcing", { +test_that("relational mutate(sd(a), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9882,52 +10398,42 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-enforcing", tmp_expr }, { - tmp_expr <- expr_window( - expr_function("lead", list(x = expr_reference("a"))), - list(expr_reference("g")), - list(), - offset_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1L, experimental = experimental) - } else { - expr_constant(1L) - }, - default_expr = if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1000, experimental = experimental) - } else { - expr_constant(1000) - } - ) - expr_set_alias(tmp_expr, "lead(a, default = 1000)") + tmp_expr <- expr_window(expr_function("stddev", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "sd(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, default = 1000)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("sd(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, default = 1000)` = c(1000, 3, 1000, 5, 6, 1000), + `sd(a)` = c(NA, 0.7071067811865476, 0.7071067811865476, 1, 1, 1), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(min(a)) order-enforcing", { +test_that("relational mutate(lag(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9947,38 +10453,52 @@ test_that("relational mutate(min(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("min", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "min(a)") + tmp_expr <- expr_window( + expr_function("lag", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lag(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("min(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `min(a)` = rep(1, 6L), + `lag(a)` = c(NA, 1, 2, 3, 4, 5), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(min(a), .by = g) order-enforcing", { +test_that("relational mutate(lag(a), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -9998,38 +10518,52 @@ test_that("relational mutate(min(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("min", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "min(a)") + tmp_expr <- expr_window( + expr_function("lag", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lag(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("min(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `min(a)` = c(1, 2, 2, 4, 4, 4), + `lag(a)` = c(NA, NA, 2, NA, 4, 5), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(max(a)) order-enforcing", { +test_that("relational mutate(lead(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10049,38 +10583,52 @@ test_that("relational mutate(max(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("max", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "max(a)") + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lead(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("max(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `max(a)` = rep(6, 6L), + `lead(a)` = c(2, 3, 4, 5, 6, NA), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(max(a), .by = g) order-enforcing", { +test_that("relational mutate(lead(a), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10100,38 +10648,52 @@ test_that("relational mutate(max(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("max", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "max(a)") + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lead(a)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("max(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `max(a)` = c(1, 3, 3, 6, 6, 6), + `lead(a)` = c(NA, 3, NA, 5, 6, NA), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(first(a)) order-enforcing", { +test_that("relational mutate(lag(a, 2)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10151,38 +10713,52 @@ test_that("relational mutate(first(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("first_value", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "first(a)") + tmp_expr <- expr_window( + expr_function("lag", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2, experimental = experimental) + } else { + expr_constant(2) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lag(a, 2)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("first(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 2)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `first(a)` = rep(1, 6L), + `lag(a, 2)` = c(NA, NA, 1, 2, 3, 4), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(first(a), .by = g) order-enforcing", { +test_that("relational mutate(lag(a, 2), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10202,38 +10778,52 @@ test_that("relational mutate(first(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("first_value", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "first(a)") + tmp_expr <- expr_window( + expr_function("lag", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2, experimental = experimental) + } else { + expr_constant(2) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lag(a, 2)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("first(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 2)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `first(a)` = c(1, 2, 2, 4, 4, 4), + `lag(a, 2)` = rep(c(NA, 4), c(5L, 1L)), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(last(a)) order-enforcing", { +test_that("relational mutate(lead(a, 2)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10253,38 +10843,52 @@ test_that("relational mutate(last(a)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("last_value", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "last(a)") + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2, experimental = experimental) + } else { + expr_constant(2) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lead(a, 2)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("last(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 2)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `last(a)` = rep(6, 6L), + `lead(a, 2)` = c(3, 4, 5, 6, NA, NA), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(last(a), .by = g) order-enforcing", { +test_that("relational mutate(lead(a, 2), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10304,38 +10908,52 @@ test_that("relational mutate(last(a), .by = g) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_window(expr_function("last_value", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) - expr_set_alias(tmp_expr, "last(a)") + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2, experimental = experimental) + } else { + expr_constant(2) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lead(a, 2)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("last(a)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 2)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `last(a)` = c(1, 3, 3, 6, 6, 6), + `lead(a, 2)` = c(NA, NA, NA, 6, NA, NA), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(nth(a, 2)) order-enforcing", { +test_that("relational mutate(lag(a, 4)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10356,53 +10974,51 @@ test_that("relational mutate(nth(a, 2)) order-enforcing", { }, { tmp_expr <- expr_window( - expr_function( - "nth_value", - list( - expr_reference("a"), - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2, experimental = experimental) - } else { - expr_constant(2) - } - ) - ), + expr_function("lag", list(x = expr_reference("a"))), list(), list(), - offset_expr = NULL, + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(4, experimental = experimental) + } else { + expr_constant(4) + }, default_expr = NULL ) - expr_set_alias(tmp_expr, "nth(a, 2)") + expr_set_alias(tmp_expr, "lag(a, 4)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("nth(a, 2)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 4)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `nth(a, 2)` = rep(2, 6L), + `lag(a, 4)` = c(NA, NA, NA, NA, 1, 2), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(nth(a, 2), .by = g) order-enforcing", { +test_that("relational mutate(lag(a, 4), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10423,59 +11039,51 @@ test_that("relational mutate(nth(a, 2), .by = g) order-enforcing", { }, { tmp_expr <- expr_window( - expr_function( - "nth_value", - list( - expr_reference("a"), - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(2, experimental = experimental) - } else { - expr_constant(2) - } - ) - ), + expr_function("lag", list(x = expr_reference("a"))), list(expr_reference("g")), list(), - offset_expr = NULL, + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(4, experimental = experimental) + } else { + expr_constant(4) + }, default_expr = NULL ) - expr_set_alias(tmp_expr, "nth(a, 2)") + expr_set_alias(tmp_expr, "lag(a, 4)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("nth(a, 2)")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, 4)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `nth(a, 2)` = c(NA, 3, 3, 5, 5, 5), + `lag(a, 4)` = rep(NA_real_, 6L), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(a / b) order-enforcing", { +test_that("relational mutate(lead(a, 4)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible( - dbExecute( - con, - r"[CREATE MACRO "___divide"(x, y) AS CASE WHEN y = 0 THEN CASE WHEN x = 0 THEN CAST('NaN' AS double) WHEN x > 0 THEN CAST('+Infinity' AS double) ELSE CAST('-Infinity' AS double) END ELSE CAST(x AS double) / y END]" - ) - ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10495,44 +11103,52 @@ test_that("relational mutate(a / b) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_function("___divide", list(expr_reference("a"), expr_reference("b"))) - expr_set_alias(tmp_expr, "a/b") + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(4, experimental = experimental) + } else { + expr_constant(4) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lead(a, 4)") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("a/b")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 4)")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a/b` = seq(0.5, 3, by = 0.5), + `lead(a, 4)` = c(5, 6, NA, NA, NA, NA), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enforcing", { +test_that("relational mutate(lead(a, 4), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible( - dbExecute( - con, - r"[CREATE MACRO "___divide"(x, y) AS CASE WHEN y = 0 THEN CASE WHEN x = 0 THEN CAST('NaN' AS double) WHEN x > 0 THEN CAST('+Infinity' AS double) ELSE CAST('-Infinity' AS double) END ELSE CAST(x AS double) / y END]" - ) - ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10552,18 +11168,54 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enfo tmp_expr }, { - tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(0, experimental = experimental) - } else { - expr_constant(0) - } - expr_set_alias(tmp_expr, "d") + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(4, experimental = experimental) + } else { + expr_constant(4) + }, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "lead(a, 4)") tmp_expr } ) ) - rel3 <- rel_project( + "arrange" + rel3 <- rel_order( rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, 4)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `lead(a, 4)` = rep(NA_real_, 6L), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(lag(a, default = 0)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -10581,29 +11233,58 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enfo tmp_expr }, { - tmp_expr <- expr_reference("d") - expr_set_alias(tmp_expr, "d") - tmp_expr - }, - { - tmp_expr <- expr_function( - "___divide", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - }, - expr_reference("d") - ) + tmp_expr <- expr_window( + expr_function("lag", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } ) - expr_set_alias(tmp_expr, "e") + expr_set_alias(tmp_expr, "lag(a, default = 0)") tmp_expr } ) ) - rel4 <- rel_project( - rel3, + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, default = 0)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `lag(a, default = 0)` = seq(0, 5, by = 1), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(lag(a, default = 0), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -10621,34 +11302,58 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enfo tmp_expr }, { - tmp_expr <- expr_reference("d") - expr_set_alias(tmp_expr, "d") - tmp_expr - }, - { - tmp_expr <- expr_reference("e") - expr_set_alias(tmp_expr, "e") - tmp_expr - }, - { - tmp_expr <- expr_function( - "___divide", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(0, experimental = experimental) - } else { - expr_constant(0) - }, - expr_reference("d") - ) + tmp_expr <- expr_window( + expr_function("lag", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } ) - expr_set_alias(tmp_expr, "f") + expr_set_alias(tmp_expr, "lag(a, default = 0)") tmp_expr } ) ) - rel5 <- rel_project( - rel4, + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lag(a, default = 0)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `lag(a, default = 0)` = c(0, 0, 2, 0, 4, 5), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(lead(a, default = 1000)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -10661,19 +11366,923 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enfo tmp_expr }, { - tmp_expr <- expr_function( - "___divide", - list( - expr_function( - "-", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - } - ) - ), + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1000, experimental = experimental) + } else { + expr_constant(1000) + } + ) + expr_set_alias(tmp_expr, "lead(a, default = 1000)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, default = 1000)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `lead(a, default = 1000)` = c(2, 3, 4, 5, 6, 1000), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(lead(a, default = 1000), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window( + expr_function("lead", list(x = expr_reference("a"))), + list(expr_reference("g")), + list(), + offset_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + }, + default_expr = if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1000, experimental = experimental) + } else { + expr_constant(1000) + } + ) + expr_set_alias(tmp_expr, "lead(a, default = 1000)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("lead(a, default = 1000)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `lead(a, default = 1000)` = c(1000, 3, 1000, 5, 6, 1000), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(min(a)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("min", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "min(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("min(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `min(a)` = rep(1, 6L), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(min(a), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("min", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "min(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("min(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `min(a)` = c(1, 2, 2, 4, 4, 4), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(max(a)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("max", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "max(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("max(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `max(a)` = rep(6, 6L), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(max(a), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("max", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "max(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("max(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `max(a)` = c(1, 3, 3, 6, 6, 6), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(first(a)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("first_value", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "first(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("first(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `first(a)` = rep(1, 6L), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(first(a), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("first_value", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "first(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("first(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `first(a)` = c(1, 2, 2, 4, 4, 4), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(last(a)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("last_value", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "last(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("last(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `last(a)` = rep(6, 6L), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(last(a), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("last_value", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "last(a)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("last(a)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `last(a)` = c(1, 3, 3, 6, 6, 6), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(nth(a, 2)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window( + expr_function( + "nth_value", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2, experimental = experimental) + } else { + expr_constant(2) + } + ) + ), + list(), + list(), + offset_expr = NULL, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "nth(a, 2)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("nth(a, 2)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `nth(a, 2)` = rep(2, 6L), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(nth(a, 2), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window( + expr_function( + "nth_value", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(2, experimental = experimental) + } else { + expr_constant(2) + } + ) + ), + list(expr_reference("g")), + list(), + offset_expr = NULL, + default_expr = NULL + ) + expr_set_alias(tmp_expr, "nth(a, 2)") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("nth(a, 2)")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `nth(a, 2)` = c(NA, 3, 3, 5, 5, 5), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(a / b) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible( + dbExecute( + con, + r"[CREATE MACRO "___divide"(x, y) AS CASE WHEN y = 0 THEN CASE WHEN x = 0 THEN CAST('NaN' AS double) WHEN x > 0 THEN CAST('+Infinity' AS double) ELSE CAST('-Infinity' AS double) END ELSE CAST(x AS double) / y END]" + ) + ) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_function("___divide", list(expr_reference("a"), expr_reference("b"))) + expr_set_alias(tmp_expr, "a/b") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("a/b")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + `a/b` = seq(0.5, 3, by = 0.5), + check.names = FALSE + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible( + dbExecute( + con, + r"[CREATE MACRO "___divide"(x, y) AS CASE WHEN y = 0 THEN CASE WHEN x = 0 THEN CAST('NaN' AS double) WHEN x > 0 THEN CAST('+Infinity' AS double) ELSE CAST('-Infinity' AS double) END ELSE CAST(x AS double) / y END]" + ) + ) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + "mutate" + rel3 <- rel_project( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_function( + "___divide", + list( + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + }, + expr_reference("d") + ) + ) + expr_set_alias(tmp_expr, "e") + tmp_expr + } + ) + ) + "mutate" + rel4 <- rel_project( + rel3, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_reference("e") + expr_set_alias(tmp_expr, "e") + tmp_expr + }, + { + tmp_expr <- expr_function( + "___divide", + list( + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + }, + expr_reference("d") + ) + ) + expr_set_alias(tmp_expr, "f") + tmp_expr + } + ) + ) + "mutate" + rel5 <- rel_project( + rel4, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_function( + "___divide", + list( + expr_function( + "-", + list( + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) + ), expr_reference("d") ) ) @@ -10681,56 +12290,621 @@ test_that("relational mutate(d = 0, e = 1 / d, f = 0 / d, g = -1 / d) order-enfo tmp_expr }, { - tmp_expr <- expr_reference("d") - expr_set_alias(tmp_expr, "d") + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_reference("e") + expr_set_alias(tmp_expr, "e") + tmp_expr + }, + { + tmp_expr <- expr_reference("f") + expr_set_alias(tmp_expr, "f") + tmp_expr + } + ) + ) + "arrange" + rel6 <- rel_order( + rel5, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d"), expr_reference("e"), expr_reference("f")) + ) + rel6 + out <- rel_to_altrep(rel6) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = rep(-Inf, 6L), + d = numeric(6), + e = rep(Inf, 6L), + f = rep(NaN, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log(d))) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible( + dbExecute( + con, + r"[CREATE MACRO "___log"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE ln(x) END]" + ) + ) + invisible(dbExecute(con, 'CREATE MACRO "suppressWarnings"(x) AS (x)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) + ) + "mutate" + rel3 <- rel_project( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_function( + "-", + list( + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) + ) + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + "mutate" + rel4 <- rel_project( + rel3, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_function("___log", list(expr_reference("c"))) + expr_set_alias(tmp_expr, "e") + tmp_expr + } + ) + ) + "mutate" + rel5 <- rel_project( + rel4, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_reference("e") + expr_set_alias(tmp_expr, "e") + tmp_expr + }, + { + tmp_expr <- expr_function("suppressWarnings", list(expr_function("___log", list(expr_reference("d"))))) + expr_set_alias(tmp_expr, "f") + tmp_expr + } + ) + ) + "arrange" + rel6 <- rel_order( + rel5, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d"), expr_reference("e"), expr_reference("f")) + ) + rel6 + out <- rel_to_altrep(rel6) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + c = numeric(6), + d = rep(-1, 6L), + e = rep(-Inf, 6L), + f = rep(NaN, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(log10(d))) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible( + dbExecute( + con, + r"[CREATE MACRO "___log10"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE log10(x) END]" + ) + ) + invisible(dbExecute(con, 'CREATE MACRO "suppressWarnings"(x) AS (x)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) + ) + "mutate" + rel3 <- rel_project( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_function( + "-", + list( + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) + ) + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + "mutate" + rel4 <- rel_project( + rel3, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_function("___log10", list(expr_reference("c"))) + expr_set_alias(tmp_expr, "e") + tmp_expr + } + ) + ) + "mutate" + rel5 <- rel_project( + rel4, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_reference("e") + expr_set_alias(tmp_expr, "e") + tmp_expr + }, + { + tmp_expr <- expr_function("suppressWarnings", list(expr_function("___log10", list(expr_reference("d"))))) + expr_set_alias(tmp_expr, "f") + tmp_expr + } + ) + ) + "arrange" + rel6 <- rel_order( + rel5, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d"), expr_reference("e"), expr_reference("f")) + ) + rel6 + out <- rel_to_altrep(rel6) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + c = numeric(6), + d = rep(-1, 6L), + e = rep(-Inf, 6L), + f = rep(NaN, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(c = 10, d = log(c)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible( + dbExecute( + con, + r"[CREATE MACRO "___log"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE ln(x) END]" + ) + ) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(10, experimental = experimental) + } else { + expr_constant(10) + } + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) + ) + "mutate" + rel3 <- rel_project( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_function("___log", list(expr_reference("c"))) + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + "arrange" + rel4 <- rel_order( + rel3, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d")) + ) + rel4 + out <- rel_to_altrep(rel4) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + c = rep(10, 6L), + d = rep(2.302585092994046, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(c = 10, d = log10(c)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible( + dbExecute( + con, + r"[CREATE MACRO "___log10"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE log10(x) END]" + ) + ) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(10, experimental = experimental) + } else { + expr_constant(10) + } + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) + ) + "mutate" + rel3 <- rel_project( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") tmp_expr }, { - tmp_expr <- expr_reference("e") - expr_set_alias(tmp_expr, "e") + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") tmp_expr }, { - tmp_expr <- expr_reference("f") - expr_set_alias(tmp_expr, "f") + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + }, + { + tmp_expr <- expr_function("___log10", list(expr_reference("c"))) + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel6 <- rel_order( - rel5, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d"), expr_reference("e"), expr_reference("f")) + "arrange" + rel4 <- rel_order( + rel3, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d")) ) - rel6 - out <- rel_to_altrep(rel6) - expect_equal( + rel4 + out <- rel_to_altrep(rel4) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), - g = rep(-Inf, 6L), - d = numeric(6), - e = rep(Inf, 6L), - f = rep(NaN, 6L) + g = c(1L, 2L, 2L, 3L, 3L, 3L), + c = rep(10, 6L), + d = rep(1, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log(d))) order-enforcing", { +test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute( con, - r"[CREATE MACRO "___log"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE ln(x) END]" + 'CREATE MACRO "grepl"(pattern, x) AS (CASE WHEN x IS NULL THEN FALSE ELSE regexp_matches(x, pattern) END)' ) ) - invisible(dbExecute(con, 'CREATE MACRO "suppressWarnings"(x) AS (x)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10751,15 +12925,16 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log }, { tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(0, experimental = experimental) + expr_constant(NA_character_, experimental = experimental) } else { - expr_constant(0) + expr_constant(NA_character_) } expr_set_alias(tmp_expr, "c") tmp_expr } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -10785,13 +12960,14 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log }, { tmp_expr <- expr_function( - "-", + "grepl", list( if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) + expr_constant(".", experimental = experimental) } else { - expr_constant(1) - } + expr_constant(".") + }, + expr_reference("c") ) ) expr_set_alias(tmp_expr, "d") @@ -10799,8 +12975,39 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log } ) ) - rel4 <- rel_project( + "arrange" + rel4 <- rel_order( rel3, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d")) + ) + rel4 + out <- rel_to_altrep(rel4) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + c = rep(NA_character_, 6L), + d = logical(6) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = a %in% NA_real_) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "is.na"(x) AS (x IS NULL OR isnan(x))')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -10818,24 +13025,43 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") - tmp_expr - }, - { - tmp_expr <- expr_reference("d") + tmp_expr <- expr_function("is.na", list(expr_reference("a"))) expr_set_alias(tmp_expr, "d") tmp_expr - }, - { - tmp_expr <- expr_function("___log", list(expr_reference("c"))) - expr_set_alias(tmp_expr, "e") - tmp_expr } ) ) - rel5 <- rel_project( - rel4, + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + d = logical(6) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = a %in% NULL) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -10853,62 +13079,195 @@ test_that("relational mutate(c = 0, d = -1, e = log(c), f = suppressWarnings(log tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + d = logical(6) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = a %in% integer()) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") tmp_expr }, { - tmp_expr <- expr_reference("d") - expr_set_alias(tmp_expr, "d") + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") tmp_expr }, { - tmp_expr <- expr_reference("e") - expr_set_alias(tmp_expr, "e") + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") tmp_expr }, { - tmp_expr <- expr_function("suppressWarnings", list(expr_function("___log", list(expr_reference("d"))))) - expr_set_alias(tmp_expr, "f") + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(FALSE, experimental = experimental) + } else { + expr_constant(FALSE) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel6 <- rel_order( - rel5, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d"), expr_reference("e"), expr_reference("f")) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) ) - rel6 - out <- rel_to_altrep(rel6) - expect_equal( + rel3 + out <- rel_to_altrep(rel3) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = numeric(6), - d = rep(-1, 6L), - e = rep(-Inf, 6L), - f = rep(NaN, 6L) + d = logical(6) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(log10(d))) order-enforcing", { +test_that("relational mutate(d = NA_real_, e = is.na(d)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible( - dbExecute( - con, - r"[CREATE MACRO "___log10"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE log10(x) END]" + invisible(dbExecute(con, 'CREATE MACRO "is.na"(x) AS (x IS NULL OR isnan(x))')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA_real_, experimental = experimental) + } else { + expr_constant(NA_real_) + } + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + "mutate" + rel3 <- rel_project( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") + tmp_expr + }, + { + tmp_expr <- expr_function("is.na", list(expr_reference("d"))) + expr_set_alias(tmp_expr, "e") + tmp_expr + } + ) + ) + "arrange" + rel4 <- rel_order( + rel3, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d"), expr_reference("e")) + ) + rel4 + out <- rel_to_altrep(rel4) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + d = rep(NA_real_, 6L), + e = rep(TRUE, 6L) ) ) - invisible(dbExecute(con, 'CREATE MACRO "suppressWarnings"(x) AS (x)')) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = NaN, e = is.na(d)) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "is.na"(x) AS (x IS NULL OR isnan(x))')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -10929,15 +13288,16 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l }, { tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(0, experimental = experimental) + expr_constant(NaN, experimental = experimental) } else { - expr_constant(0) + expr_constant(NaN) } - expr_set_alias(tmp_expr, "c") + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) + "mutate" rel3 <- rel_project( rel2, list( @@ -10957,28 +13317,50 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") + tmp_expr <- expr_reference("d") + expr_set_alias(tmp_expr, "d") tmp_expr }, { - tmp_expr <- expr_function( - "-", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) - } - ) - ) - expr_set_alias(tmp_expr, "d") + tmp_expr <- expr_function("is.na", list(expr_reference("d"))) + expr_set_alias(tmp_expr, "e") tmp_expr } ) ) - rel4 <- rel_project( + "arrange" + rel4 <- rel_order( rel3, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d"), expr_reference("e")) + ) + rel4 + out <- rel_to_altrep(rel4) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + d = rep(NaN, 6L), + e = rep(TRUE, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = row_number()) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -10996,24 +13378,44 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") - tmp_expr - }, - { - tmp_expr <- expr_reference("d") + tmp_expr <- expr_function( + "r_base::as.integer", + list( + expr_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL) + ) + ) expr_set_alias(tmp_expr, "d") tmp_expr - }, - { - tmp_expr <- expr_function("___log10", list(expr_reference("c"))) - expr_set_alias(tmp_expr, "e") - tmp_expr } ) ) - rel5 <- rel_project( - rel4, + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), d = 1:6) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = row_number(), .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(rapi_load_rfuns(drv@database_ref)) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -11031,61 +13433,46 @@ test_that("relational mutate(c = 0, d = -1, e = log10(c), f = suppressWarnings(l tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") - tmp_expr - }, - { - tmp_expr <- expr_reference("d") + tmp_expr <- expr_function( + "r_base::as.integer", + list( + expr_window(expr_function("row_number", list()), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL) + ) + ) expr_set_alias(tmp_expr, "d") tmp_expr - }, - { - tmp_expr <- expr_reference("e") - expr_set_alias(tmp_expr, "e") - tmp_expr - }, - { - tmp_expr <- expr_function("suppressWarnings", list(expr_function("___log10", list(expr_reference("d"))))) - expr_set_alias(tmp_expr, "f") - tmp_expr } ) ) - rel6 <- rel_order( - rel5, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d"), expr_reference("e"), expr_reference("f")) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) ) - rel6 - out <- rel_to_altrep(rel6) - expect_equal( + rel3 + out <- rel_to_altrep(rel3) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = numeric(6), - d = rep(-1, 6L), - e = rep(-Inf, 6L), - f = rep(NaN, 6L) + d = c(1L, 1L, 2L, 1L, 2L, 3L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = 10, d = log(c)) order-enforcing", { +test_that("relational mutate(c = .data$b) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible( - dbExecute( - con, - r"[CREATE MACRO "___log"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE ln(x) END]" - ) - ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -11105,18 +13492,44 @@ test_that("relational mutate(c = 10, d = log(c)) order-enforcing", { tmp_expr }, { - tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(10, experimental = experimental) - } else { - expr_constant(10) - } + tmp_expr <- expr_reference("b") expr_set_alias(tmp_expr, "c") tmp_expr } ) ) - rel3 <- rel_project( + "arrange" + rel3 <- rel_order( rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + c = rep(2, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = NA) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "___null"() AS CAST(NULL AS BOOLEAN)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -11134,49 +13547,41 @@ test_that("relational mutate(c = 10, d = log(c)) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") - tmp_expr - }, - { - tmp_expr <- expr_function("___log", list(expr_reference("c"))) + tmp_expr <- expr_function("___null", list()) expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel4 <- rel_order( - rel3, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d")) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) ) - rel4 - out <- rel_to_altrep(rel4) - expect_equal( + rel3 + out <- rel_to_altrep(rel3) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = rep(10, 6L), - d = rep(2.302585092994046, 6L) + d = rep(NA, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = 10, d = log10(c)) order-enforcing", { +test_that("relational mutate(d = NA_integer_) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible( - dbExecute( - con, - r"[CREATE MACRO "___log10"(x) AS CASE WHEN x < 0 THEN CAST('NaN' AS double) WHEN x = 0 THEN CAST('-Inf' AS double) ELSE log10(x) END]" - ) - ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -11197,79 +13602,44 @@ test_that("relational mutate(c = 10, d = log10(c)) order-enforcing", { }, { tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(10, experimental = experimental) + expr_constant(NA_integer_, experimental = experimental) } else { - expr_constant(10) + expr_constant(NA_integer_) } - expr_set_alias(tmp_expr, "c") - tmp_expr - } - ) - ) - rel3 <- rel_project( - rel2, - list( - { - tmp_expr <- expr_reference("a") - expr_set_alias(tmp_expr, "a") - tmp_expr - }, - { - tmp_expr <- expr_reference("b") - expr_set_alias(tmp_expr, "b") - tmp_expr - }, - { - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }, - { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") - tmp_expr - }, - { - tmp_expr <- expr_function("___log10", list(expr_reference("c"))) expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel4 <- rel_order( - rel3, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d")) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) ) - rel4 - out <- rel_to_altrep(rel4) - expect_equal( + rel3 + out <- rel_to_altrep(rel3) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = rep(10, 6L), - d = rep(1, 6L) + d = rep(NA_integer_, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-enforcing", { - skip_if_not(TEST_RE2) - +test_that("relational mutate(d = NA_real_) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible( - dbExecute( - con, - 'CREATE MACRO "grepl"(pattern, x) AS (CASE WHEN x IS NULL THEN FALSE ELSE regexp_matches(x, pattern) END)' - ) - ) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -11290,17 +13660,46 @@ test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-enforci }, { tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(NA_character_, experimental = experimental) + expr_constant(NA_real_, experimental = experimental) } else { - expr_constant(NA_character_) + expr_constant(NA_real_) } - expr_set_alias(tmp_expr, "c") + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel3 <- rel_project( + "arrange" + rel3 <- rel_order( rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) + ) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame( + a = seq(1, 6, by = 1), + b = rep(2, 6L), + g = c(1L, 2L, 2L, 3L, 3L, 3L), + d = rep(NA_real_, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational mutate(d = NA_character_) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "mutate" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" + rel2 <- rel_project( + rel1, list( { tmp_expr <- expr_reference("a") @@ -11318,53 +13717,53 @@ test_that("relational mutate(c = NA_character_, d = grepl('.', c)) order-enforci tmp_expr }, { - tmp_expr <- expr_reference("c") - expr_set_alias(tmp_expr, "c") - tmp_expr - }, - { - tmp_expr <- expr_function( - "grepl", - list( - if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(".", experimental = experimental) - } else { - expr_constant(".") - }, - expr_reference("c") - ) - ) + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA_character_, experimental = experimental) + } else { + expr_constant(NA_character_) + } expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel4 <- rel_order( - rel3, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d")) + "arrange" + rel3 <- rel_order( + rel2, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) ) - rel4 - out <- rel_to_altrep(rel4) - expect_equal( + rel3 + out <- rel_to_altrep(rel3) + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = rep(NA_character_, 6L), - d = logical(6) + d = rep(NA_character_, 6L) ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(c = .data$b) order-enforcing", { +test_that("relational mutate(d = if_else(a > 1, \"ok\", NA)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE + invisible( + dbExecute( + con, + 'CREATE MACRO "if_else"(test, yes, no) AS (CASE WHEN test THEN yes ELSE no END)' + ) + ) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO ">"(x, y) AS "r_base::>"(x, y)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "mutate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "mutate" rel2 <- rel_project( rel1, list( @@ -11384,25 +13783,51 @@ test_that("relational mutate(c = .data$b) order-enforcing", { tmp_expr }, { - tmp_expr <- expr_reference("b") - expr_set_alias(tmp_expr, "c") + tmp_expr <- expr_function( + "if_else", + list( + expr_function( + ">", + list( + expr_reference("a"), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + ) + ), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant("ok", experimental = experimental) + } else { + expr_constant("ok") + }, + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(NA, experimental = experimental) + } else { + expr_constant(NA) + } + ) + ) + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) + "arrange" rel3 <- rel_order( rel2, - list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c")) + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("d")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame( a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = rep(2, 6L) + d = rep(c(NA, "ok"), c(1L, 5L)) ) ) dbDisconnect(con, shutdown = TRUE) @@ -11412,11 +13837,14 @@ test_that("relational mutate(c = .data$b) order-enforcing", { test_that("relational relocate(g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11439,7 +13867,7 @@ test_that("relational relocate(g) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -11448,11 +13876,14 @@ test_that("relational relocate(g) order-preserving", { test_that("relational relocate(a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11475,7 +13906,7 @@ test_that("relational relocate(a) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -11484,11 +13915,14 @@ test_that("relational relocate(a) order-preserving", { test_that("relational relocate(g, .before = b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11511,7 +13945,7 @@ test_that("relational relocate(g, .before = b) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), g = c(1L, 2L, 2L, 3L, 3L, 3L), b = rep(2, 6L)) ) @@ -11520,11 +13954,14 @@ test_that("relational relocate(g, .before = b) order-preserving", { test_that("relational relocate(a:b, .after = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11547,7 +13984,7 @@ test_that("relational relocate(a:b, .after = g) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -11558,11 +13995,14 @@ test_that("relational relocate(a:b, .after = g) order-preserving", { test_that("relational relocate(g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11583,13 +14023,14 @@ test_that("relational relocate(g) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("g"), expr_reference("a"), expr_reference("b")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -11598,11 +14039,14 @@ test_that("relational relocate(g) order-enforcing", { test_that("relational relocate(a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11623,13 +14067,14 @@ test_that("relational relocate(a) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -11638,11 +14083,14 @@ test_that("relational relocate(a) order-enforcing", { test_that("relational relocate(g, .before = b) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11663,13 +14111,14 @@ test_that("relational relocate(g, .before = b) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("g"), expr_reference("b")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), g = c(1L, 2L, 2L, 3L, 3L, 3L), b = rep(2, 6L)) ) @@ -11678,11 +14127,14 @@ test_that("relational relocate(g, .before = b) order-enforcing", { test_that("relational relocate(a:b, .after = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "relocate" rel1 <- rel_from_df(con, df1, experimental = experimental) + "relocate" rel2 <- rel_project( rel1, list( @@ -11703,13 +14155,14 @@ test_that("relational relocate(a:b, .after = g) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("g"), expr_reference("a"), expr_reference("b")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -11720,11 +14173,14 @@ test_that("relational relocate(a:b, .after = g) order-enforcing", { test_that("relational rename() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "rename" rel1 <- rel_from_df(con, df1, experimental = experimental) + "rename" rel2 <- rel_project( rel1, list( @@ -11747,7 +14203,7 @@ test_that("relational rename() order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -11756,11 +14212,14 @@ test_that("relational rename() order-preserving", { test_that("relational rename(c = a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "rename" rel1 <- rel_from_df(con, df1, experimental = experimental) + "rename" rel2 <- rel_project( rel1, list( @@ -11783,7 +14242,7 @@ test_that("relational rename(c = a) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(c = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -11794,11 +14253,14 @@ test_that("relational rename(c = a) order-preserving", { test_that("relational rename() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "rename" rel1 <- rel_from_df(con, df1, experimental = experimental) + "rename" rel2 <- rel_project( rel1, list( @@ -11819,13 +14281,14 @@ test_that("relational rename() order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -11834,11 +14297,14 @@ test_that("relational rename() order-enforcing", { test_that("relational rename(c = a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "rename" rel1 <- rel_from_df(con, df1, experimental = experimental) + "rename" rel2 <- rel_project( rel1, list( @@ -11859,13 +14325,14 @@ test_that("relational rename(c = a) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("c"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(c = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -11876,19 +14343,25 @@ test_that("relational rename(c = a) order-enforcing", { test_that("relational right_join(join_by(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "right_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "right_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "right_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "right_join" rel4 <- rel_set_alias(rel3, "rhs") + "right_join" rel5 <- rel_project( rel2, list( @@ -11904,6 +14377,7 @@ test_that("relational right_join(join_by(a)) order-preserving", { } ) ) + "right_join" rel6 <- rel_project( rel4, list( @@ -11919,6 +14393,7 @@ test_that("relational right_join(join_by(a)) order-preserving", { } ) ) + "right_join" rel7 <- rel_project( rel5, list( @@ -11939,6 +14414,7 @@ test_that("relational right_join(join_by(a)) order-preserving", { } ) ) + "right_join" rel8 <- rel_project( rel6, list( @@ -11959,6 +14435,7 @@ test_that("relational right_join(join_by(a)) order-preserving", { } ) ) + "right_join" rel9 <- rel_join( rel7, rel8, @@ -11967,10 +14444,12 @@ test_that("relational right_join(join_by(a)) order-preserving", { ), "right" ) + "right_join" rel10 <- rel_order( rel9, list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8)) ) + "right_join" rel11 <- rel_project( rel10, list( @@ -11993,7 +14472,7 @@ test_that("relational right_join(join_by(a)) order-preserving", { ) rel11 out <- rel_to_altrep(rel11) - expect_equal( + expect_identical( out, data.frame(a = 2:5, b.x = c(2, 2, 2, NA), b.y = rep(2, 4L)) ) @@ -12004,19 +14483,25 @@ test_that("relational right_join(join_by(a)) order-preserving", { test_that("relational right_join(join_by(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "right_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "right_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "right_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "right_join" rel4 <- rel_set_alias(rel3, "rhs") + "right_join" rel5 <- rel_project( rel2, list( @@ -12032,6 +14517,7 @@ test_that("relational right_join(join_by(a)) order-enforcing", { } ) ) + "right_join" rel6 <- rel_project( rel4, list( @@ -12047,6 +14533,7 @@ test_that("relational right_join(join_by(a)) order-enforcing", { } ) ) + "right_join" rel7 <- rel_join( rel5, rel6, @@ -12055,6 +14542,7 @@ test_that("relational right_join(join_by(a)) order-enforcing", { ), "right" ) + "right_join" rel8 <- rel_project( rel7, list( @@ -12075,13 +14563,14 @@ test_that("relational right_join(join_by(a)) order-enforcing", { } ) ) + "arrange" rel9 <- rel_order( rel8, list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y")) ) rel9 out <- rel_to_altrep(rel9) - expect_equal( + expect_identical( out, data.frame(a = 2:5, b.x = c(2, 2, 2, NA), b.y = rep(2, 4L)) ) @@ -12092,11 +14581,14 @@ test_that("relational right_join(join_by(a)) order-enforcing", { test_that("relational select(a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "select" rel1 <- rel_from_df(con, df1, experimental = experimental) + "select" rel2 <- rel_project( rel1, list( @@ -12109,7 +14601,7 @@ test_that("relational select(a) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1)) ) @@ -12118,11 +14610,14 @@ test_that("relational select(a) order-preserving", { test_that("relational select(-g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "select" rel1 <- rel_from_df(con, df1, experimental = experimental) + "select" rel2 <- rel_project( rel1, list( @@ -12140,7 +14635,7 @@ test_that("relational select(-g) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -12149,11 +14644,14 @@ test_that("relational select(-g) order-preserving", { test_that("relational select(everything()) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "select" rel1 <- rel_from_df(con, df1, experimental = experimental) + "select" rel2 <- rel_project( rel1, list( @@ -12176,7 +14674,7 @@ test_that("relational select(everything()) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -12187,11 +14685,14 @@ test_that("relational select(everything()) order-preserving", { test_that("relational select(a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "select" rel1 <- rel_from_df(con, df1, experimental = experimental) + "select" rel2 <- rel_project( rel1, list( @@ -12202,10 +14703,11 @@ test_that("relational select(a) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("a"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1)) ) @@ -12214,11 +14716,14 @@ test_that("relational select(a) order-enforcing", { test_that("relational select(-g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "select" rel1 <- rel_from_df(con, df1, experimental = experimental) + "select" rel2 <- rel_project( rel1, list( @@ -12234,10 +14739,11 @@ test_that("relational select(-g) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("a"), expr_reference("b"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) @@ -12246,11 +14752,14 @@ test_that("relational select(-g) order-enforcing", { test_that("relational select(everything()) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "select" rel1 <- rel_from_df(con, df1, experimental = experimental) + "select" rel2 <- rel_project( rel1, list( @@ -12271,13 +14780,14 @@ test_that("relational select(everything()) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order( rel2, list(expr_reference("a"), expr_reference("b"), expr_reference("g")) ) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) @@ -12288,19 +14798,25 @@ test_that("relational select(everything()) order-enforcing", { test_that("relational semi_join(join_by(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "semi_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "semi_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "semi_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "semi_join" rel4 <- rel_set_alias(rel3, "rhs") + "semi_join" rel5 <- rel_project( rel2, list( @@ -12321,6 +14837,7 @@ test_that("relational semi_join(join_by(a)) order-preserving", { } ) ) + "semi_join" rel6 <- rel_join( rel5, rel4, @@ -12329,7 +14846,9 @@ test_that("relational semi_join(join_by(a)) order-preserving", { ), "semi" ) + "semi_join" rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5))) + "semi_join" rel8 <- rel_project( rel7, list( @@ -12347,7 +14866,7 @@ test_that("relational semi_join(join_by(a)) order-preserving", { ) rel8 out <- rel_to_altrep(rel8) - expect_equal( + expect_identical( out, data.frame(a = 2:4, b = rep(2, 3L)) ) @@ -12358,19 +14877,25 @@ test_that("relational semi_join(join_by(a)) order-preserving", { test_that("relational semi_join(join_by(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "semi_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "semi_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "semi_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "semi_join" rel4 <- rel_set_alias(rel3, "rhs") + "semi_join" rel5 <- rel_join( rel2, rel4, @@ -12379,10 +14904,11 @@ test_that("relational semi_join(join_by(a)) order-enforcing", { ), "semi" ) + "arrange" rel6 <- rel_order(rel5, list(expr_reference("a"), expr_reference("b"))) rel6 out <- rel_to_altrep(rel6) - expect_equal( + expect_identical( out, data.frame(a = 2:4, b = rep(2, 3L)) ) @@ -12393,20 +14919,27 @@ test_that("relational semi_join(join_by(a)) order-enforcing", { test_that("relational setdiff() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "anti_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "anti_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "anti_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "anti_join" rel4 <- rel_set_alias(rel3, "rhs") + "anti_join" rel5 <- rel_project( rel2, list( @@ -12427,6 +14960,7 @@ test_that("relational setdiff() order-preserving", { } ) ) + "anti_join" rel6 <- rel_join( rel5, rel4, @@ -12436,7 +14970,9 @@ test_that("relational setdiff() order-preserving", { ), "anti" ) + "anti_join" rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5))) + "anti_join" rel8 <- rel_project( rel7, list( @@ -12452,6 +14988,7 @@ test_that("relational setdiff() order-preserving", { } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -12472,6 +15009,7 @@ test_that("relational setdiff() order-preserving", { } ) ) + "distinct" rel10 <- rel_project( rel9, list( @@ -12510,6 +15048,7 @@ test_that("relational setdiff() order-preserving", { } ) ) + "distinct" rel11 <- rel_filter( rel10, list( @@ -12526,7 +15065,9 @@ test_that("relational setdiff() order-preserving", { ) ) ) + "distinct" rel12 <- rel_order(rel11, list(expr_reference("___row_number"))) + "distinct" rel13 <- rel_project( rel12, list( @@ -12544,7 +15085,7 @@ test_that("relational setdiff() order-preserving", { ) rel13 out <- rel_to_altrep(rel13) - expect_equal( + expect_identical( out, data.frame(a = 1L, b = 2) ) @@ -12555,19 +15096,24 @@ test_that("relational setdiff() order-preserving", { test_that("relational setdiff() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "setdiff" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "setdiff" rel2 <- rel_from_df(con, df2, experimental = experimental) + "setdiff" rel3 <- rel_set_diff(rel1, rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = 1L, b = 2) ) @@ -12578,11 +15124,14 @@ test_that("relational setdiff() order-enforcing", { test_that("relational summarise(c = mean(a)) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(), @@ -12594,10 +15143,11 @@ test_that("relational summarise(c = mean(a)) order-preserving", { } ) ) + "summarise" rel3 <- rel_distinct(rel2) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(c = 3.5) ) @@ -12606,11 +15156,14 @@ test_that("relational summarise(c = mean(a)) order-preserving", { test_that("relational summarise(c = mean(a), .by = b) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_project( rel1, list( @@ -12636,6 +15189,7 @@ test_that("relational summarise(c = mean(a), .by = b) order-preserving", { } ) ) + "summarise" rel3 <- rel_aggregate( rel2, groups = list(expr_reference("b")), @@ -12652,7 +15206,9 @@ test_that("relational summarise(c = mean(a), .by = b) order-preserving", { } ) ) + "summarise" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "summarise" rel5 <- rel_project( rel4, list( @@ -12670,7 +15226,7 @@ test_that("relational summarise(c = mean(a), .by = b) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(b = 2, c = 3.5) ) @@ -12679,11 +15235,14 @@ test_that("relational summarise(c = mean(a), .by = b) order-preserving", { test_that("relational summarise(c = mean(a), .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_project( rel1, list( @@ -12709,6 +15268,7 @@ test_that("relational summarise(c = mean(a), .by = g) order-preserving", { } ) ) + "summarise" rel3 <- rel_aggregate( rel2, groups = list(expr_reference("g")), @@ -12725,7 +15285,9 @@ test_that("relational summarise(c = mean(a), .by = g) order-preserving", { } ) ) + "summarise" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "summarise" rel5 <- rel_project( rel4, list( @@ -12743,7 +15305,7 @@ test_that("relational summarise(c = mean(a), .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(g = 1:3, c = c(1, 2.5, 5)) ) @@ -12752,11 +15314,14 @@ test_that("relational summarise(c = mean(a), .by = g) order-preserving", { test_that("relational summarise(c = 1) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(), @@ -12772,10 +15337,11 @@ test_that("relational summarise(c = 1) order-preserving", { } ) ) + "summarise" rel3 <- rel_distinct(rel2) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(c = 1) ) @@ -12784,11 +15350,14 @@ test_that("relational summarise(c = 1) order-preserving", { test_that("relational summarise(c = 1, .by = g) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_project( rel1, list( @@ -12814,6 +15383,7 @@ test_that("relational summarise(c = 1, .by = g) order-preserving", { } ) ) + "summarise" rel3 <- rel_aggregate( rel2, groups = list(expr_reference("g")), @@ -12834,7 +15404,9 @@ test_that("relational summarise(c = 1, .by = g) order-preserving", { } ) ) + "summarise" rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "summarise" rel5 <- rel_project( rel4, list( @@ -12852,22 +15424,158 @@ test_that("relational summarise(c = 1, .by = g) order-preserving", { ) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(g = 1:3, c = rep(1, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) +test_that("relational summarise(n = n(), n = n() + 1L, .by = g) order-preserving", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "summarise" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" + rel2 <- rel_project( + rel1, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + }, + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL) + expr_set_alias(tmp_expr, "___row_number") + tmp_expr + } + ) + ) + "summarise" + rel3 <- rel_aggregate( + rel2, + groups = list(expr_reference("g")), + aggregates = list( + { + tmp_expr <- expr_function("min", list(expr_reference("___row_number"))) + expr_set_alias(tmp_expr, "___row_number") + tmp_expr + }, + { + tmp_expr <- expr_function( + "+", + list( + expr_function("n", list()), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + } + ) + ) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) + ) + "summarise" + rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + "summarise" + rel5 <- rel_project( + rel4, + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("n") + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) + ) + rel5 + out <- rel_to_altrep(rel5) + expect_identical( + out, + data.frame(g = 1:3, n = 2:4) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational summarise(n = n(), n = n() + 1L) order-preserving", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "summarise" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" + rel2 <- rel_aggregate( + rel1, + groups = list(), + aggregates = list( + { + tmp_expr <- expr_function( + "+", + list( + expr_function("n", list()), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + } + ) + ) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) + ) + "summarise" + rel3 <- rel_distinct(rel2) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame(n = 7L) + ) + dbDisconnect(con, shutdown = TRUE) +}) + # summarise order-enforcing ------------------------------------------------------------ test_that("relational summarise(c = mean(a)) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(), @@ -12879,11 +15587,13 @@ test_that("relational summarise(c = mean(a)) order-enforcing", { } ) ) + "summarise" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("c"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(c = 3.5) ) @@ -12892,11 +15602,14 @@ test_that("relational summarise(c = mean(a)) order-enforcing", { test_that("relational summarise(c = mean(a), .by = b) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(expr_reference("b")), @@ -12908,10 +15621,11 @@ test_that("relational summarise(c = mean(a), .by = b) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("b"), expr_reference("c"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(b = 2, c = 3.5) ) @@ -12920,11 +15634,14 @@ test_that("relational summarise(c = mean(a), .by = b) order-enforcing", { test_that("relational summarise(c = mean(a), .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(expr_reference("g")), @@ -12936,10 +15653,11 @@ test_that("relational summarise(c = mean(a), .by = g) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("c"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(g = 1:3, c = c(1, 2.5, 5)) ) @@ -12948,11 +15666,14 @@ test_that("relational summarise(c = mean(a), .by = g) order-enforcing", { test_that("relational summarise(c = 1) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(), @@ -12968,11 +15689,13 @@ test_that("relational summarise(c = 1) order-enforcing", { } ) ) + "summarise" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("c"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(c = 1) ) @@ -12981,11 +15704,14 @@ test_that("relational summarise(c = 1) order-enforcing", { test_that("relational summarise(c = 1, .by = g) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(expr_reference("g")), @@ -13001,34 +15727,130 @@ test_that("relational summarise(c = 1, .by = g) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("c"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(g = 1:3, c = rep(1, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) +test_that("relational summarise(n = n(), n = n() + 1L, .by = g) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "summarise" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" + rel2 <- rel_aggregate( + rel1, + groups = list(expr_reference("g")), + aggregates = list( + { + tmp_expr <- expr_function( + "+", + list( + expr_function("n", list()), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + } + ) + ) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) + ) + "arrange" + rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("n"))) + rel3 + out <- rel_to_altrep(rel3) + expect_identical( + out, + data.frame(g = 1:3, n = 2:4) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational summarise(n = n(), n = n() + 1L) order-enforcing", { + # Autogenerated + drv <- duckdb() + con <- dbConnect(drv) + experimental <- FALSE + invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) + df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + + "summarise" + rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" + rel2 <- rel_aggregate( + rel1, + groups = list(), + aggregates = list( + { + tmp_expr <- expr_function( + "+", + list( + expr_function("n", list()), + if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1L, experimental = experimental) + } else { + expr_constant(1L) + } + ) + ) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) + ) + "summarise" + rel3 <- rel_distinct(rel2) + "arrange" + rel4 <- rel_order(rel3, list(expr_reference("n"))) + rel4 + out <- rel_to_altrep(rel4) + expect_identical( + out, + data.frame(n = 7L) + ) + dbDisconnect(con, shutdown = TRUE) +}) + # symdiff order-preserving ------------------------------------------------------------- test_that("relational symdiff() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible( dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)') ) - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "anti_join" rel1 <- rel_from_df(con, df1, experimental = experimental) + "anti_join" rel2 <- rel_set_alias(rel1, "lhs") df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "anti_join" rel3 <- rel_from_df(con, df2, experimental = experimental) + "anti_join" rel4 <- rel_set_alias(rel3, "rhs") + "anti_join" rel5 <- rel_project( rel2, list( @@ -13049,6 +15871,7 @@ test_that("relational symdiff() order-preserving", { } ) ) + "anti_join" rel6 <- rel_join( rel5, rel4, @@ -13058,7 +15881,9 @@ test_that("relational symdiff() order-preserving", { ), "anti" ) + "anti_join" rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5))) + "anti_join" rel8 <- rel_project( rel7, list( @@ -13074,11 +15899,17 @@ test_that("relational symdiff() order-preserving", { } ) ) - df3 <- data.frame(a = 5L, b = 2) + df3 <- data.frame(a = 1L, b = 2) + "union_all" rel9 <- rel_from_df(con, df3, experimental = experimental) - rel10 <- rel_project( - rel8, + df4 <- data.frame(a = 5L, b = 2) + + "union_all" + rel10 <- rel_from_df(con, df4, experimental = experimental) + "union_all" + rel11 <- rel_project( + rel9, list( { tmp_expr <- expr_reference("a") @@ -13106,8 +15937,9 @@ test_that("relational symdiff() order-preserving", { } ) ) - rel11 <- rel_project( - rel9, + "union_all" + rel12 <- rel_project( + rel10, list( { tmp_expr <- expr_reference("a") @@ -13135,13 +15967,16 @@ test_that("relational symdiff() order-preserving", { } ) ) - rel12 <- rel_union_all(rel10, rel11) - rel13 <- rel_order( - rel12, + "union_all" + rel13 <- rel_union_all(rel11, rel12) + "union_all" + rel14 <- rel_order( + rel13, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) - rel14 <- rel_project( - rel13, + "union_all" + rel15 <- rel_project( + rel14, list( { tmp_expr <- expr_reference("a") @@ -13155,8 +15990,9 @@ test_that("relational symdiff() order-preserving", { } ) ) - rel15 <- rel_project( - rel14, + "distinct" + rel16 <- rel_project( + rel15, list( { tmp_expr <- expr_reference("a") @@ -13175,8 +16011,9 @@ test_that("relational symdiff() order-preserving", { } ) ) - rel16 <- rel_project( - rel15, + "distinct" + rel17 <- rel_project( + rel16, list( { tmp_expr <- expr_reference("a") @@ -13213,8 +16050,9 @@ test_that("relational symdiff() order-preserving", { } ) ) - rel17 <- rel_filter( - rel16, + "distinct" + rel18 <- rel_filter( + rel17, list( expr_function( "==", @@ -13229,9 +16067,11 @@ test_that("relational symdiff() order-preserving", { ) ) ) - rel18 <- rel_order(rel17, list(expr_reference("___row_number"))) - rel19 <- rel_project( - rel18, + "distinct" + rel19 <- rel_order(rel18, list(expr_reference("___row_number"))) + "distinct" + rel20 <- rel_project( + rel19, list( { tmp_expr <- expr_reference("a") @@ -13245,9 +16085,9 @@ test_that("relational symdiff() order-preserving", { } ) ) - rel19 - out <- rel_to_altrep(rel19) - expect_equal( + rel20 + out <- rel_to_altrep(rel20) + expect_identical( out, data.frame(a = c(1L, 5L), b = c(2, 2)) ) @@ -13258,19 +16098,24 @@ test_that("relational symdiff() order-preserving", { test_that("relational symdiff() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "symdiff" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "symdiff" rel2 <- rel_from_df(con, df2, experimental = experimental) + "symdiff" rel3 <- rel_set_symdiff(rel1, rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = c(1L, 5L), b = c(2, 2)) ) @@ -13281,12 +16126,15 @@ test_that("relational symdiff() order-enforcing", { test_that("relational tally() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(), @@ -13298,10 +16146,11 @@ test_that("relational tally() order-preserving", { } ) ) + "summarise" rel3 <- rel_distinct(rel2) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(n = 6L) ) @@ -13312,12 +16161,15 @@ test_that("relational tally() order-preserving", { test_that("relational tally() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)')) df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "summarise" rel1 <- rel_from_df(con, df1, experimental = experimental) + "summarise" rel2 <- rel_aggregate( rel1, groups = list(), @@ -13329,11 +16181,13 @@ test_that("relational tally() order-enforcing", { } ) ) + "summarise" rel3 <- rel_distinct(rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("n"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(n = 6L) ) @@ -13344,11 +16198,14 @@ test_that("relational tally() order-enforcing", { test_that("relational transmute(c = a + 1) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "transmute" rel1 <- rel_from_df(con, df1, experimental = experimental) + "transmute" rel2 <- rel_project( rel1, list( @@ -13371,7 +16228,7 @@ test_that("relational transmute(c = a + 1) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(c = seq(2, 7, by = 1)) ) @@ -13380,11 +16237,14 @@ test_that("relational transmute(c = a + 1) order-preserving", { test_that("relational transmute(row = a) order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "transmute" rel1 <- rel_from_df(con, df1, experimental = experimental) + "transmute" rel2 <- rel_project( rel1, list( @@ -13397,7 +16257,7 @@ test_that("relational transmute(row = a) order-preserving", { ) rel2 out <- rel_to_altrep(rel2) - expect_equal( + expect_identical( out, data.frame(row = seq(1, 6, by = 1)) ) @@ -13408,11 +16268,14 @@ test_that("relational transmute(row = a) order-preserving", { test_that("relational transmute(c = a + 1) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "transmute" rel1 <- rel_from_df(con, df1, experimental = experimental) + "transmute" rel2 <- rel_project( rel1, list( @@ -13433,10 +16296,11 @@ test_that("relational transmute(c = a + 1) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("c"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(c = seq(2, 7, by = 1)) ) @@ -13445,11 +16309,14 @@ test_that("relational transmute(c = a + 1) order-enforcing", { test_that("relational transmute(row = a) order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + "transmute" rel1 <- rel_from_df(con, df1, experimental = experimental) + "transmute" rel2 <- rel_project( rel1, list( @@ -13460,10 +16327,11 @@ test_that("relational transmute(row = a) order-enforcing", { } ) ) + "arrange" rel3 <- rel_order(rel2, list(expr_reference("row"))) rel3 out <- rel_to_altrep(rel3) - expect_equal( + expect_identical( out, data.frame(row = seq(1, 6, by = 1)) ) @@ -13474,15 +16342,20 @@ test_that("relational transmute(row = a) order-enforcing", { test_that("relational union() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE - invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y')) + invisible(rapi_load_rfuns(drv@database_ref)) + invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS "r_base::=="(x, y)')) df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -13512,6 +16385,7 @@ test_that("relational union() order-preserving", { } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -13541,11 +16415,14 @@ test_that("relational union() order-preserving", { } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -13561,6 +16438,7 @@ test_that("relational union() order-preserving", { } ) ) + "distinct" rel8 <- rel_project( rel7, list( @@ -13581,6 +16459,7 @@ test_that("relational union() order-preserving", { } ) ) + "distinct" rel9 <- rel_project( rel8, list( @@ -13619,6 +16498,7 @@ test_that("relational union() order-preserving", { } ) ) + "distinct" rel10 <- rel_filter( rel9, list( @@ -13635,7 +16515,9 @@ test_that("relational union() order-preserving", { ) ) ) + "distinct" rel11 <- rel_order(rel10, list(expr_reference("___row_number"))) + "distinct" rel12 <- rel_project( rel11, list( @@ -13653,7 +16535,7 @@ test_that("relational union() order-preserving", { ) rel12 out <- rel_to_altrep(rel12) - expect_equal( + expect_identical( out, data.frame(a = 1:5, b = rep(2, 5L)) ) @@ -13664,20 +16546,26 @@ test_that("relational union() order-preserving", { test_that("relational union() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "distinct" rel4 <- rel_distinct(rel3) + "arrange" rel5 <- rel_order(rel4, list(expr_reference("a"), expr_reference("b"))) rel5 out <- rel_to_altrep(rel5) - expect_equal( + expect_identical( out, data.frame(a = 1:5, b = rep(2, 5L)) ) @@ -13688,14 +16576,18 @@ test_that("relational union() order-enforcing", { test_that("relational union_all() order-preserving", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_project( rel1, list( @@ -13725,6 +16617,7 @@ test_that("relational union_all() order-preserving", { } ) ) + "union_all" rel4 <- rel_project( rel2, list( @@ -13754,11 +16647,14 @@ test_that("relational union_all() order-preserving", { } ) ) + "union_all" rel5 <- rel_union_all(rel3, rel4) + "union_all" rel6 <- rel_order( rel5, list(expr_reference("___row_number_x"), expr_reference("___row_number_y")) ) + "union_all" rel7 <- rel_project( rel6, list( @@ -13776,7 +16672,7 @@ test_that("relational union_all() order-preserving", { ) rel7 out <- rel_to_altrep(rel7) - expect_equal( + expect_identical( out, data.frame(a = c(1L, 2L, 3L, 4L, 2L, 3L, 4L, 5L), b = rep(2, 8L)) ) @@ -13787,19 +16683,24 @@ test_that("relational union_all() order-preserving", { test_that("relational union_all() order-enforcing", { # Autogenerated - con <- dbConnect(duckdb()) + drv <- duckdb() + con <- dbConnect(drv) experimental <- FALSE df1 <- data.frame(a = 1:4, b = rep(2, 4L)) + "union_all" rel1 <- rel_from_df(con, df1, experimental = experimental) df2 <- data.frame(a = 2:5, b = rep(2, 4L)) + "union_all" rel2 <- rel_from_df(con, df2, experimental = experimental) + "union_all" rel3 <- rel_union_all(rel1, rel2) + "arrange" rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b"))) rel4 out <- rel_to_altrep(rel4) - expect_equal( + expect_identical( out, data.frame(a = c(1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L), b = rep(2, 8L)) )