diff --git a/tests/testthat/test-rel_api.R b/tests/testthat/test-rel_api.R index 550b1829d..154831dfa 100644 --- a/tests/testthat/test-rel_api.R +++ b/tests/testthat/test-rel_api.R @@ -9,14 +9,14 @@ test_that("relational anti_join(join_by(a)) order-preserving", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -82,14 +82,14 @@ test_that("relational anti_join(join_by(a)) order-enforcing", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -117,14 +117,14 @@ test_that("relational arrange() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) rel1 out <- rel_to_altrep(rel1) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -133,7 +133,7 @@ test_that("relational arrange(a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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"))) @@ -141,7 +141,7 @@ test_that("relational arrange(a) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -150,7 +150,7 @@ test_that("relational arrange(g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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("g"))) @@ -158,7 +158,7 @@ test_that("relational arrange(g) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -167,7 +167,7 @@ test_that("relational arrange(g, a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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("g"), expr_reference("a"))) @@ -175,7 +175,7 @@ test_that("relational arrange(g, a) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -184,7 +184,7 @@ test_that("relational arrange(a, g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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("g"))) @@ -192,7 +192,7 @@ test_that("relational arrange(a, g) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -203,7 +203,7 @@ test_that("relational arrange() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_from_df(con, df1, experimental = experimental) @@ -215,7 +215,7 @@ test_that("relational arrange() order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -224,7 +224,7 @@ test_that("relational arrange(a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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"))) @@ -236,7 +236,7 @@ test_that("relational arrange(a) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -245,7 +245,7 @@ test_that("relational arrange(g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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("g"))) @@ -257,7 +257,7 @@ test_that("relational arrange(g) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -266,7 +266,7 @@ test_that("relational arrange(g, a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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("g"), expr_reference("a"))) @@ -278,7 +278,7 @@ test_that("relational arrange(g, a) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -287,7 +287,7 @@ test_that("relational arrange(a, g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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("g"))) @@ -299,7 +299,7 @@ test_that("relational arrange(a, g) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -310,22 +310,23 @@ test_that("relational count() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel3 <- rel_distinct(rel2) - rel3 - out <- rel_to_altrep(rel3) + rel2 + out <- rel_to_altrep(rel2) expect_equal( out, data.frame(n = 6L) @@ -337,24 +338,42 @@ test_that("relational count(a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("a")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + a = { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) + ) + rel3 + out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), n = c(1L, 1L, 1L, 1L, 1L, 1L)) + data.frame(a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -363,21 +382,39 @@ test_that("relational count(b) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("b")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + b = { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + } + ) + ) + rel3 + out <- rel_to_altrep(rel3) expect_equal( out, data.frame(b = 2, n = 6L) @@ -389,21 +426,39 @@ test_that("relational count(g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("g")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + g = { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) + ) + rel3 + out <- rel_to_altrep(rel3) expect_equal( out, data.frame(g = 1:3, n = 1:3) @@ -415,28 +470,52 @@ test_that("relational count(g, a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("g"), expr_reference("a")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + g = { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + a = { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) + ) + rel3 + out <- rel_to_altrep(rel3) expect_equal( out, - data.frame( - g = c(1L, 2L, 2L, 3L, 3L, 3L), - a = c(1, 2, 3, 4, 5, 6), - n = c(1L, 1L, 1L, 1L, 1L, 1L) - ) + data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -445,24 +524,52 @@ test_that("relational count(b, g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("b"), expr_reference("g")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + b = { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + g = { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel3 <- rel_order( + rel2, + list( + { + 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 + } + ) + ) + rel3 + out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(b = c(2, 2, 2), g = 1:3, n = 1:3) + data.frame(b = rep(2, 3L), g = 1:3, n = 1:3) ) dbDisconnect(con, shutdown = TRUE) }) @@ -473,23 +580,24 @@ test_that("relational count() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel3 <- rel_distinct(rel2) - rel4 <- rel_order(rel3, list(expr_reference("n"))) - rel4 - out <- rel_to_altrep(rel4) + rel3 <- rel_order(rel2, list(expr_reference("n"))) + rel3 + out <- rel_to_altrep(rel3) expect_equal( out, data.frame(n = 6L) @@ -501,25 +609,43 @@ test_that("relational count(a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("a")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + a = { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel3 <- rel_order(rel2, list(expr_reference("a"), expr_reference("n"))) - rel3 - out <- rel_to_altrep(rel3) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) + ) + rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("n"))) + rel4 + out <- rel_to_altrep(rel4) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), n = c(1L, 1L, 1L, 1L, 1L, 1L)) + data.frame(a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -528,22 +654,40 @@ test_that("relational count(b) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("b")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + b = { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel3 <- rel_order(rel2, list(expr_reference("b"), expr_reference("n"))) - rel3 - out <- rel_to_altrep(rel3) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + } + ) + ) + rel4 <- rel_order(rel3, list(expr_reference("b"), expr_reference("n"))) + rel4 + out <- rel_to_altrep(rel4) expect_equal( out, data.frame(b = 2, n = 6L) @@ -555,22 +699,40 @@ test_that("relational count(g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("g")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + g = { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) - rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("n"))) - rel3 - out <- rel_to_altrep(rel3) + rel3 <- rel_order( + rel2, + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) + ) + rel4 <- rel_order(rel3, list(expr_reference("g"), expr_reference("n"))) + rel4 + out <- rel_to_altrep(rel4) expect_equal( out, data.frame(g = 1:3, n = 1:3) @@ -582,32 +744,56 @@ test_that("relational count(g, a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("g"), expr_reference("a")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + g = { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + a = { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) rel3 <- rel_order( rel2, + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + }, + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) + ) + rel4 <- rel_order( + rel3, list(expr_reference("g"), expr_reference("a"), expr_reference("n")) ) - rel3 - out <- rel_to_altrep(rel3) + rel4 + out <- rel_to_altrep(rel4) expect_equal( out, - data.frame( - g = c(1L, 2L, 2L, 3L, 3L, 3L), - a = c(1, 2, 3, 4, 5, 6), - n = c(1L, 1L, 1L, 1L, 1L, 1L) - ) + data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), n = rep(1L, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -616,28 +802,56 @@ test_that("relational count(b, g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, - groups = list(expr_reference("b"), expr_reference("g")), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + groups = list( + b = { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + g = { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ), + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) rel3 <- rel_order( rel2, + list( + { + 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 + } + ) + ) + rel4 <- rel_order( + rel3, list(expr_reference("b"), expr_reference("g"), expr_reference("n")) ) - rel3 - out <- rel_to_altrep(rel3) + rel4 + out <- rel_to_altrep(rel4) expect_equal( out, - data.frame(b = c(2, 2, 2), g = 1:3, n = 1:3) + data.frame(b = rep(2, 3L), g = 1:3, n = 1:3) ) dbDisconnect(con, shutdown = TRUE) }) @@ -648,8 +862,8 @@ test_that("relational distinct() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -766,7 +980,7 @@ test_that("relational distinct() order-preserving", { out <- rel_to_altrep(rel6) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -775,8 +989,8 @@ test_that("relational distinct(a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -851,17 +1065,19 @@ test_that("relational distinct(a) order-preserving", { rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) rel6 <- rel_project( rel5, - list({ - tmp_expr <- expr_reference("a") - expr_set_alias(tmp_expr, "a") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) ) rel6 out <- rel_to_altrep(rel6) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6)) + data.frame(a = seq(1, 6, by = 1)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -870,8 +1086,8 @@ test_that("relational distinct(a, b) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -973,7 +1189,7 @@ test_that("relational distinct(a, b) order-preserving", { out <- rel_to_altrep(rel6) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -982,8 +1198,8 @@ test_that("relational distinct(b, b) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -1058,11 +1274,13 @@ test_that("relational distinct(b, b) order-preserving", { rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) rel6 <- rel_project( rel5, - list({ - tmp_expr <- expr_reference("b") - expr_set_alias(tmp_expr, "b") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + } + ) ) rel6 out <- rel_to_altrep(rel6) @@ -1077,8 +1295,8 @@ test_that("relational distinct(g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -1153,11 +1371,13 @@ test_that("relational distinct(g) order-preserving", { rel5 <- rel_order(rel4, list(expr_reference("___row_number"))) rel6 <- rel_project( rel5, - list({ - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) ) rel6 out <- rel_to_altrep(rel6) @@ -1172,8 +1392,8 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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) df2 <- data.frame(a = 1L, b = 3, g = 2L) @@ -1252,11 +1472,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( rel7 <- rel_order(rel6, list(expr_reference("___row_number"))) rel8 <- rel_project( rel7, - list({ - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) ) rel8 out <- rel_to_altrep(rel8) @@ -1271,8 +1493,8 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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) df2 <- data.frame(a = 1L, b = 4, g = 2L) @@ -1351,11 +1573,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( rel7 <- rel_order(rel6, list(expr_reference("___row_number"))) rel8 <- rel_project( rel7, - list({ - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) ) rel8 out <- rel_to_altrep(rel8) @@ -1370,8 +1594,8 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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) df2 <- data.frame(a = 1L, b = 5, g = 2L) @@ -1450,11 +1674,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( rel7 <- rel_order(rel6, list(expr_reference("___row_number"))) rel8 <- rel_project( rel7, - list({ - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) ) rel8 out <- rel_to_altrep(rel8) @@ -1469,8 +1695,8 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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) df2 <- data.frame(a = 1L, b = 6, g = 2L) @@ -1549,11 +1775,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( rel7 <- rel_order(rel6, list(expr_reference("___row_number"))) rel8 <- rel_project( rel7, - list({ - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) ) rel8 out <- rel_to_altrep(rel8) @@ -1568,8 +1796,8 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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) df2 <- data.frame(a = 1L, b = 7, g = 2L) @@ -1648,11 +1876,13 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( rel7 <- rel_order(rel6, list(expr_reference("___row_number"))) rel8 <- rel_project( rel7, - list({ - tmp_expr <- expr_reference("g") - expr_set_alias(tmp_expr, "g") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("g") + expr_set_alias(tmp_expr, "g") + tmp_expr + } + ) ) rel8 out <- rel_to_altrep(rel8) @@ -1667,8 +1897,8 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -1775,7 +2005,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-preserving", { out <- rel_to_altrep(rel6) expect_equal( out, - data.frame(a = c(1, 2, 4), b = c(2, 2, 2), g = 1:3) + data.frame(a = c(1, 2, 4), b = rep(2, 3L), g = 1:3) ) dbDisconnect(con, shutdown = TRUE) }) @@ -1786,7 +2016,7 @@ test_that("relational distinct() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_distinct(rel1) @@ -1798,7 +2028,7 @@ test_that("relational distinct() order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -1807,7 +2037,7 @@ test_that("relational distinct(a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -1826,7 +2056,7 @@ test_that("relational distinct(a) order-enforcing", { out <- rel_to_altrep(rel4) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6)) + data.frame(a = seq(1, 6, by = 1)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -1835,7 +2065,7 @@ test_that("relational distinct(a, b) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -1859,7 +2089,7 @@ test_that("relational distinct(a, b) order-enforcing", { out <- rel_to_altrep(rel4) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -1868,7 +2098,7 @@ test_that("relational distinct(b, b) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -1896,7 +2126,7 @@ test_that("relational distinct(g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -1924,7 +2154,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) df2 <- data.frame(a = 1L, b = 3, g = 2L) @@ -1956,7 +2186,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) df2 <- data.frame(a = 1L, b = 4, g = 2L) @@ -1988,7 +2218,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) df2 <- data.frame(a = 1L, b = 5, g = 2L) @@ -2020,7 +2250,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) df2 <- data.frame(a = 1L, b = 6, g = 2L) @@ -2052,7 +2282,7 @@ test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct( # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) df2 <- data.frame(a = 1L, b = 7, g = 2L) @@ -2084,8 +2314,8 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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( @@ -2196,7 +2426,7 @@ test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", { out <- rel_to_altrep(rel7) expect_equal( out, - data.frame(a = c(1, 2, 4), b = c(2, 2, 2), g = 1:3) + data.frame(a = c(1, 2, 4), b = rep(2, 3L), g = 1:3) ) dbDisconnect(con, shutdown = TRUE) }) @@ -2207,8 +2437,8 @@ test_that("relational filter(a == 1) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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_filter( @@ -2241,8 +2471,8 @@ test_that("relational filter(a %in% 2:3, g == 2) order-preserving", { con <- dbConnect(duckdb()) experimental <- FALSE invisible(dbExecute(con, "CREATE MACRO \"|\"(x, y) AS (x OR y)")) - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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_filter( @@ -2303,8 +2533,8 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", { experimental <- FALSE invisible(dbExecute(con, "CREATE MACRO \"&\"(x, y) AS (x AND y)")) invisible(dbExecute(con, "CREATE MACRO \"|\"(x, y) AS (x OR y)")) - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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_filter( @@ -2370,8 +2600,8 @@ test_that("relational filter(a == 1) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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_filter( @@ -2408,8 +2638,8 @@ test_that("relational filter(a %in% 2:3, g == 2) order-enforcing", { con <- dbConnect(duckdb()) experimental <- FALSE invisible(dbExecute(con, "CREATE MACRO \"|\"(x, y) AS (x OR y)")) - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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_filter( @@ -2474,8 +2704,8 @@ test_that("relational filter(a %in% 2:3 & g == 2) order-enforcing", { experimental <- FALSE invisible(dbExecute(con, "CREATE MACRO \"&\"(x, y) AS (x AND y)")) invisible(dbExecute(con, "CREATE MACRO \"|\"(x, y) AS (x OR y)")) - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + 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_filter( @@ -2548,15 +2778,15 @@ test_that("relational full_join(join_by(a)) order-preserving", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(a, b) AS COALESCE(a, b)")) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(x, y) AS COALESCE(x, y)")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -2672,7 +2902,7 @@ test_that("relational full_join(join_by(a)) order-preserving", { out <- rel_to_altrep(rel11) expect_equal( out, - data.frame(a = 1:5, b.x = c(2, 2, 2, 2, NA), b.y = c(NA, 2, 2, 2, 2)) + data.frame(a = 1:5, b.x = rep(c(2, NA), c(4L, 1L)), b.y = rep(c(NA, 2), c(1L, 4L))) ) dbDisconnect(con, shutdown = TRUE) }) @@ -2686,15 +2916,15 @@ test_that("relational full_join(join_by(a)) order-enforcing", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(a, b) AS COALESCE(a, b)")) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(x, y) AS COALESCE(x, y)")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -2770,7 +3000,7 @@ test_that("relational full_join(join_by(a)) order-enforcing", { out <- rel_to_altrep(rel9) expect_equal( out, - data.frame(a = 1:5, b.x = c(2, 2, 2, 2, NA), b.y = c(NA, 2, 2, 2, 2)) + data.frame(a = 1:5, b.x = rep(c(2, NA), c(4L, 1L)), b.y = rep(c(NA, 2), c(1L, 4L))) ) dbDisconnect(con, shutdown = TRUE) }) @@ -2784,14 +3014,15 @@ test_that("relational inner_join(join_by(a)) order-preserving", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(x, y) AS COALESCE(x, y)")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -2884,7 +3115,10 @@ test_that("relational inner_join(join_by(a)) order-preserving", { rel10, list( { - tmp_expr <- expr_reference("a_x") + tmp_expr <- expr_function( + "___coalesce", + list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)) + ) expr_set_alias(tmp_expr, "a") tmp_expr }, @@ -2904,7 +3138,7 @@ test_that("relational inner_join(join_by(a)) order-preserving", { out <- rel_to_altrep(rel11) expect_equal( out, - data.frame(a = 2:4, b.x = c(2, 2, 2), b.y = c(2, 2, 2)) + data.frame(a = 2:4, b.x = rep(2, 3L), b.y = rep(2, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -2918,14 +3152,15 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(x, y) AS COALESCE(x, y)")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -2974,7 +3209,10 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { rel7, list( { - tmp_expr <- expr_reference("a_x") + tmp_expr <- expr_function( + "___coalesce", + list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)) + ) expr_set_alias(tmp_expr, "a") tmp_expr }, @@ -2998,7 +3236,7 @@ test_that("relational inner_join(join_by(a)) order-enforcing", { out <- rel_to_altrep(rel9) expect_equal( out, - data.frame(a = 2:4, b.x = c(2, 2, 2), b.y = c(2, 2, 2)) + data.frame(a = 2:4, b.x = rep(2, 3L), b.y = rep(2, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -3009,10 +3247,10 @@ test_that("relational intersect() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_set_intersect(rel1, rel2) @@ -3020,7 +3258,7 @@ test_that("relational intersect() order-preserving", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = 2:4, b = c(2, 2, 2)) + data.frame(a = 2:4, b = rep(2, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -3031,10 +3269,10 @@ test_that("relational intersect() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_set_intersect(rel1, rel2) @@ -3043,7 +3281,7 @@ test_that("relational intersect() order-enforcing", { out <- rel_to_altrep(rel4) expect_equal( out, - data.frame(a = 2:4, b = c(2, 2, 2)) + data.frame(a = 2:4, b = rep(2, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -3057,14 +3295,15 @@ test_that("relational left_join(join_by(a)) order-preserving", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(x, y) AS COALESCE(x, y)")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -3157,7 +3396,10 @@ test_that("relational left_join(join_by(a)) order-preserving", { rel10, list( { - tmp_expr <- expr_reference("a_x") + tmp_expr <- expr_function( + "___coalesce", + list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)) + ) expr_set_alias(tmp_expr, "a") tmp_expr }, @@ -3177,7 +3419,7 @@ test_that("relational left_join(join_by(a)) order-preserving", { out <- rel_to_altrep(rel11) expect_equal( out, - data.frame(a = 1:4, b.x = c(2, 2, 2, 2), b.y = c(NA, 2, 2, 2)) + data.frame(a = 1:4, b.x = rep(2, 4L), b.y = c(NA, 2, 2, 2)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -3191,14 +3433,15 @@ test_that("relational left_join(join_by(a)) order-enforcing", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"___coalesce\"(x, y) AS COALESCE(x, y)")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -3247,7 +3490,10 @@ test_that("relational left_join(join_by(a)) order-enforcing", { rel7, list( { - tmp_expr <- expr_reference("a_x") + tmp_expr <- expr_function( + "___coalesce", + list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)) + ) expr_set_alias(tmp_expr, "a") tmp_expr }, @@ -3271,7 +3517,7 @@ test_that("relational left_join(join_by(a)) order-enforcing", { out <- rel_to_altrep(rel9) expect_equal( out, - data.frame(a = 1:4, b.x = c(2, 2, 2, 2), b.y = c(NA, 2, 2, 2)) + data.frame(a = 1:4, b.x = rep(2, 4L), b.y = c(NA, 2, 2, 2)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -3282,14 +3528,14 @@ test_that("relational mutate() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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) rel1 out <- rel_to_altrep(rel1) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -3298,7 +3544,7 @@ test_that("relational mutate(a + 1) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3341,10 +3587,10 @@ test_that("relational mutate(a + 1) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a + 1` = c(2, 3, 4, 5, 6, 7), + `a + 1` = seq(2, 7, by = 1), check.names = FALSE ) ) @@ -3355,7 +3601,7 @@ test_that("relational mutate(a + 1, .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3454,10 +3700,10 @@ test_that("relational mutate(a + 1, .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a + 1` = c(2, 3, 4, 5, 6, 7), + `a + 1` = seq(2, 7, by = 1), check.names = FALSE ) ) @@ -3468,7 +3714,7 @@ test_that("relational mutate(c = a + 1) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3511,10 +3757,10 @@ test_that("relational mutate(c = a + 1) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = c(2, 3, 4, 5, 6, 7) + c = seq(2, 7, by = 1) ) ) dbDisconnect(con, shutdown = TRUE) @@ -3524,7 +3770,7 @@ test_that("relational mutate(`if` = a + 1) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3567,10 +3813,10 @@ test_that("relational mutate(`if` = a + 1) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `if` = c(2, 3, 4, 5, 6, 7), + `if` = seq(2, 7, by = 1), check.names = FALSE ) ) @@ -3581,7 +3827,7 @@ test_that("relational mutate(sum(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3614,10 +3860,10 @@ test_that("relational mutate(sum(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sum(a)` = c(21, 21, 21, 21, 21, 21), + `sum(a)` = rep(21, 6L), check.names = FALSE ) ) @@ -3628,7 +3874,7 @@ test_that("relational mutate(sum(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3717,8 +3963,8 @@ test_that("relational mutate(sum(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -3731,7 +3977,7 @@ test_that("relational mutate(mean(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3764,10 +4010,10 @@ test_that("relational mutate(mean(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `mean(a)` = c(3.5, 3.5, 3.5, 3.5, 3.5, 3.5), + `mean(a)` = rep(3.5, 6L), check.names = FALSE ) ) @@ -3778,7 +4024,7 @@ test_that("relational mutate(mean(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3867,8 +4113,8 @@ test_that("relational mutate(mean(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -3881,7 +4127,7 @@ test_that("relational mutate(sd(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -3914,13 +4160,10 @@ test_that("relational mutate(sd(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sd(a)` = c( - 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0, - 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0 - ), + `sd(a)` = rep(0x1.deeea11683f49p+0, 6L), check.names = FALSE ) ) @@ -3931,7 +4174,7 @@ test_that("relational mutate(sd(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4020,10 +4263,10 @@ test_that("relational mutate(sd(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sd(a)` = c(NA, 0.7071067811865475727373, 0.7071067811865475727373, 1, 1, 1), + `sd(a)` = c(NA, 0.7071067811865476, 0.7071067811865476, 1, 1, 1), check.names = FALSE ) ) @@ -4034,7 +4277,7 @@ test_that("relational mutate(lag(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4077,8 +4320,8 @@ test_that("relational mutate(lag(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -4091,7 +4334,7 @@ test_that("relational mutate(lag(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4190,8 +4433,8 @@ test_that("relational mutate(lag(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -4204,7 +4447,7 @@ test_that("relational mutate(lead(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4247,8 +4490,8 @@ test_that("relational mutate(lead(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -4261,7 +4504,7 @@ test_that("relational mutate(lead(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4360,8 +4603,8 @@ test_that("relational mutate(lead(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -4374,7 +4617,7 @@ test_that("relational mutate(lag(a, 2)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4417,8 +4660,8 @@ test_that("relational mutate(lag(a, 2)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -4431,7 +4674,7 @@ test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4530,10 +4773,10 @@ test_that("relational mutate(lag(a, 2), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 2)` = c(NA, NA, NA, NA, NA, 4), + `lag(a, 2)` = rep(c(NA, 4), c(5L, 1L)), check.names = FALSE ) ) @@ -4544,7 +4787,7 @@ test_that("relational mutate(lead(a, 2)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4587,8 +4830,8 @@ test_that("relational mutate(lead(a, 2)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), check.names = FALSE @@ -4601,7 +4844,7 @@ test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4700,8 +4943,8 @@ test_that("relational mutate(lead(a, 2), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), check.names = FALSE @@ -4714,7 +4957,7 @@ test_that("relational mutate(lag(a, 4)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4757,8 +5000,8 @@ test_that("relational mutate(lag(a, 4)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -4771,7 +5014,7 @@ test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4870,10 +5113,10 @@ test_that("relational mutate(lag(a, 4), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 4)` = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), + `lag(a, 4)` = rep(NA_real_, 6L), check.names = FALSE ) ) @@ -4884,7 +5127,7 @@ test_that("relational mutate(lead(a, 4)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -4927,8 +5170,8 @@ test_that("relational mutate(lead(a, 4)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), check.names = FALSE @@ -4941,7 +5184,7 @@ test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5040,10 +5283,10 @@ test_that("relational mutate(lead(a, 4), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, 4)` = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), + `lead(a, 4)` = rep(NA_real_, 6L), check.names = FALSE ) ) @@ -5054,7 +5297,7 @@ test_that("relational mutate(lag(a, default = 0)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5101,10 +5344,10 @@ test_that("relational mutate(lag(a, default = 0)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, default = 0)` = c(0, 1, 2, 3, 4, 5), + `lag(a, default = 0)` = seq(0, 5, by = 1), check.names = FALSE ) ) @@ -5115,7 +5358,7 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5218,8 +5461,8 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -5232,7 +5475,7 @@ test_that("relational mutate(lead(a, default = 1000)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5279,8 +5522,8 @@ test_that("relational mutate(lead(a, default = 1000)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -5293,7 +5536,7 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving" # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5396,8 +5639,8 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-preserving" expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -5410,7 +5653,7 @@ test_that("relational mutate(min(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5443,10 +5686,10 @@ test_that("relational mutate(min(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `min(a)` = c(1, 1, 1, 1, 1, 1), + `min(a)` = rep(1, 6L), check.names = FALSE ) ) @@ -5457,7 +5700,7 @@ test_that("relational mutate(min(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5546,8 +5789,8 @@ test_that("relational mutate(min(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -5560,7 +5803,7 @@ test_that("relational mutate(max(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5593,10 +5836,10 @@ test_that("relational mutate(max(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `max(a)` = c(6, 6, 6, 6, 6, 6), + `max(a)` = rep(6, 6L), check.names = FALSE ) ) @@ -5607,7 +5850,7 @@ test_that("relational mutate(max(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5696,8 +5939,8 @@ test_that("relational mutate(max(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -5710,7 +5953,7 @@ test_that("relational mutate(first(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5743,10 +5986,10 @@ test_that("relational mutate(first(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `first(a)` = c(1, 1, 1, 1, 1, 1), + `first(a)` = rep(1, 6L), check.names = FALSE ) ) @@ -5757,7 +6000,7 @@ test_that("relational mutate(first(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5846,8 +6089,8 @@ test_that("relational mutate(first(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -5860,7 +6103,7 @@ test_that("relational mutate(last(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5893,21 +6136,187 @@ test_that("relational mutate(last(a)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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-preserving", { + # 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") + 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 + } + ) + ) + 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("___row_number") + expr_set_alias(tmp_expr, "___row_number") + 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 + } + ) + ) + rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + 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("last(a)") + expr_set_alias(tmp_expr, "last(a)") + tmp_expr + } + ) + ) + rel5 + out <- rel_to_altrep(rel5) + expect_equal( + 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-preserving", { + # 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") + 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 + } + ) + ) + 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), - `last(a)` = c(6, 6, 6, 6, 6, 6), + `nth(a, 2)` = rep(2, 6L), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(last(a), .by = g) order-preserving", { +test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -5959,8 +6368,24 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { 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( + "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 } ) @@ -5985,8 +6410,8 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { tmp_expr }, { - tmp_expr <- expr_reference("last(a)") - expr_set_alias(tmp_expr, "last(a)") + tmp_expr <- expr_reference("nth(a, 2)") + expr_set_alias(tmp_expr, "nth(a, 2)") tmp_expr } ) @@ -5996,21 +6421,27 @@ test_that("relational mutate(last(a), .by = g) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), + `nth(a, 2)` = c(NA, 3, 3, 5, 5, 5), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(nth(a, 2)) order-preserving", { +test_that("relational mutate(a / b) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible( + dbExecute( + con, + "CREATE MACRO \"___divide\"(x, y) AS CASE WHEN x = 0 AND y = 0 THEN CAST('NaN' AS double) 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_project( @@ -6032,24 +6463,8 @@ test_that("relational mutate(nth(a, 2)) order-preserving", { 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 <- expr_function("___divide", list(expr_reference("a"), expr_reference("b"))) + expr_set_alias(tmp_expr, "a/b") tmp_expr } ) @@ -6059,21 +6474,27 @@ test_that("relational mutate(nth(a, 2)) order-preserving", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `nth(a, 2)` = c(2, 2, 2, 2, 2, 2), + `a/b` = seq(0.5, 3, by = 0.5), check.names = FALSE ) ) dbDisconnect(con, shutdown = TRUE) }) -test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { +test_that("relational mutate(c = 0, d = 0, e = c / d) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + invisible( + dbExecute( + con, + "CREATE MACRO \"___divide\"(x, y) AS CASE WHEN x = 0 AND y = 0 THEN CAST('NaN' AS double) 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_project( @@ -6095,8 +6516,12 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { 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 <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } + expr_set_alias(tmp_expr, "c") tmp_expr } ) @@ -6120,36 +6545,23 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { tmp_expr }, { - tmp_expr <- expr_reference("___row_number") - expr_set_alias(tmp_expr, "___row_number") + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") 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 <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } + expr_set_alias(tmp_expr, "d") tmp_expr } ) ) - rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) - rel5 <- rel_project( - rel4, + rel4 <- rel_project( + rel3, list( { tmp_expr <- expr_reference("a") @@ -6167,22 +6579,33 @@ test_that("relational mutate(nth(a, 2), .by = g) order-preserving", { tmp_expr }, { - tmp_expr <- expr_reference("nth(a, 2)") - expr_set_alias(tmp_expr, "nth(a, 2)") + 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("___divide", list(expr_reference("c"), expr_reference("d"))) + expr_set_alias(tmp_expr, "e") tmp_expr } ) ) - rel5 - out <- rel_to_altrep(rel5) + rel4 + out <- rel_to_altrep(rel4) expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 + c = numeric(6), + d = numeric(6), + e = rep(NaN, 6L) ) ) dbDisconnect(con, shutdown = TRUE) @@ -6194,7 +6617,7 @@ test_that("relational mutate() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6205,7 +6628,7 @@ test_that("relational mutate() order-enforcing", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -6214,7 +6637,7 @@ test_that("relational mutate(a + 1) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6261,10 +6684,10 @@ test_that("relational mutate(a + 1) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a + 1` = c(2, 3, 4, 5, 6, 7), + `a + 1` = seq(2, 7, by = 1), check.names = FALSE ) ) @@ -6275,7 +6698,7 @@ test_that("relational mutate(a + 1, .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6322,10 +6745,10 @@ test_that("relational mutate(a + 1, .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `a + 1` = c(2, 3, 4, 5, 6, 7), + `a + 1` = seq(2, 7, by = 1), check.names = FALSE ) ) @@ -6336,7 +6759,7 @@ test_that("relational mutate(c = a + 1) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6383,10 +6806,10 @@ test_that("relational mutate(c = a + 1) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - c = c(2, 3, 4, 5, 6, 7) + c = seq(2, 7, by = 1) ) ) dbDisconnect(con, shutdown = TRUE) @@ -6396,7 +6819,7 @@ test_that("relational mutate(`if` = a + 1) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6443,10 +6866,10 @@ test_that("relational mutate(`if` = a + 1) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `if` = c(2, 3, 4, 5, 6, 7), + `if` = seq(2, 7, by = 1), check.names = FALSE ) ) @@ -6457,7 +6880,7 @@ test_that("relational mutate(sum(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6494,10 +6917,10 @@ test_that("relational mutate(sum(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sum(a)` = c(21, 21, 21, 21, 21, 21), + `sum(a)` = rep(21, 6L), check.names = FALSE ) ) @@ -6508,7 +6931,7 @@ test_that("relational mutate(sum(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6545,8 +6968,8 @@ test_that("relational mutate(sum(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -6559,7 +6982,7 @@ test_that("relational mutate(mean(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6596,10 +7019,10 @@ test_that("relational mutate(mean(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `mean(a)` = c(3.5, 3.5, 3.5, 3.5, 3.5, 3.5), + `mean(a)` = rep(3.5, 6L), check.names = FALSE ) ) @@ -6610,7 +7033,7 @@ test_that("relational mutate(mean(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6647,8 +7070,8 @@ test_that("relational mutate(mean(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -6661,7 +7084,7 @@ test_that("relational mutate(sd(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6698,13 +7121,10 @@ test_that("relational mutate(sd(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sd(a)` = c( - 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0, - 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0, 0x1.deeea11683f49p+0 - ), + `sd(a)` = rep(0x1.deeea11683f49p+0, 6L), check.names = FALSE ) ) @@ -6715,7 +7135,7 @@ test_that("relational mutate(sd(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6752,10 +7172,10 @@ test_that("relational mutate(sd(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `sd(a)` = c(NA, 0.7071067811865475727373, 0.7071067811865475727373, 1, 1, 1), + `sd(a)` = c(NA, 0.7071067811865476, 0.7071067811865476, 1, 1, 1), check.names = FALSE ) ) @@ -6766,7 +7186,7 @@ test_that("relational mutate(lag(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6813,8 +7233,8 @@ test_that("relational mutate(lag(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -6827,7 +7247,7 @@ test_that("relational mutate(lag(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6874,8 +7294,8 @@ test_that("relational mutate(lag(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -6888,7 +7308,7 @@ test_that("relational mutate(lead(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6935,8 +7355,8 @@ test_that("relational mutate(lead(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -6949,7 +7369,7 @@ test_that("relational mutate(lead(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -6996,8 +7416,8 @@ test_that("relational mutate(lead(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7010,7 +7430,7 @@ test_that("relational mutate(lag(a, 2)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7057,8 +7477,8 @@ test_that("relational mutate(lag(a, 2)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7071,7 +7491,7 @@ test_that("relational mutate(lag(a, 2), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7118,10 +7538,10 @@ test_that("relational mutate(lag(a, 2), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 2)` = c(NA, NA, NA, NA, NA, 4), + `lag(a, 2)` = rep(c(NA, 4), c(5L, 1L)), check.names = FALSE ) ) @@ -7132,7 +7552,7 @@ test_that("relational mutate(lead(a, 2)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7179,8 +7599,8 @@ test_that("relational mutate(lead(a, 2)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), check.names = FALSE @@ -7193,7 +7613,7 @@ test_that("relational mutate(lead(a, 2), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7240,8 +7660,8 @@ test_that("relational mutate(lead(a, 2), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), check.names = FALSE @@ -7254,7 +7674,7 @@ test_that("relational mutate(lag(a, 4)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7301,8 +7721,8 @@ test_that("relational mutate(lag(a, 4)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7315,7 +7735,7 @@ test_that("relational mutate(lag(a, 4), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7362,10 +7782,10 @@ test_that("relational mutate(lag(a, 4), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, 4)` = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), + `lag(a, 4)` = rep(NA_real_, 6L), check.names = FALSE ) ) @@ -7376,7 +7796,7 @@ test_that("relational mutate(lead(a, 4)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7423,8 +7843,8 @@ test_that("relational mutate(lead(a, 4)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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), check.names = FALSE @@ -7437,7 +7857,7 @@ test_that("relational mutate(lead(a, 4), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7484,10 +7904,10 @@ test_that("relational mutate(lead(a, 4), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lead(a, 4)` = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), + `lead(a, 4)` = rep(NA_real_, 6L), check.names = FALSE ) ) @@ -7498,7 +7918,7 @@ test_that("relational mutate(lag(a, default = 0)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7549,10 +7969,10 @@ test_that("relational mutate(lag(a, default = 0)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `lag(a, default = 0)` = c(0, 1, 2, 3, 4, 5), + `lag(a, default = 0)` = seq(0, 5, by = 1), check.names = FALSE ) ) @@ -7563,7 +7983,7 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7614,8 +8034,8 @@ test_that("relational mutate(lag(a, default = 0), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7628,7 +8048,7 @@ test_that("relational mutate(lead(a, default = 1000)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7679,8 +8099,8 @@ test_that("relational mutate(lead(a, default = 1000)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7693,7 +8113,7 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-enforcing", # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7744,8 +8164,8 @@ test_that("relational mutate(lead(a, default = 1000), .by = g) order-enforcing", expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7758,7 +8178,7 @@ test_that("relational mutate(min(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7795,10 +8215,10 @@ test_that("relational mutate(min(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `min(a)` = c(1, 1, 1, 1, 1, 1), + `min(a)` = rep(1, 6L), check.names = FALSE ) ) @@ -7809,7 +8229,7 @@ test_that("relational mutate(min(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7846,8 +8266,8 @@ test_that("relational mutate(min(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7860,7 +8280,7 @@ test_that("relational mutate(max(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7897,10 +8317,10 @@ test_that("relational mutate(max(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `max(a)` = c(6, 6, 6, 6, 6, 6), + `max(a)` = rep(6, 6L), check.names = FALSE ) ) @@ -7911,7 +8331,7 @@ test_that("relational mutate(max(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7948,8 +8368,8 @@ test_that("relational mutate(max(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -7962,7 +8382,7 @@ test_that("relational mutate(first(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -7999,10 +8419,10 @@ test_that("relational mutate(first(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `first(a)` = c(1, 1, 1, 1, 1, 1), + `first(a)` = rep(1, 6L), check.names = FALSE ) ) @@ -8013,7 +8433,7 @@ test_that("relational mutate(first(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8050,8 +8470,8 @@ test_that("relational mutate(first(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -8064,7 +8484,7 @@ test_that("relational mutate(last(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8101,10 +8521,10 @@ test_that("relational mutate(last(a)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `last(a)` = c(6, 6, 6, 6, 6, 6), + `last(a)` = rep(6, 6L), check.names = FALSE ) ) @@ -8115,7 +8535,7 @@ test_that("relational mutate(last(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8152,8 +8572,8 @@ test_that("relational mutate(last(a), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -8166,7 +8586,7 @@ test_that("relational mutate(nth(a, 2)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8219,10 +8639,10 @@ test_that("relational mutate(nth(a, 2)) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + a = seq(1, 6, by = 1), + b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L), - `nth(a, 2)` = c(2, 2, 2, 2, 2, 2), + `nth(a, 2)` = rep(2, 6L), check.names = FALSE ) ) @@ -8233,7 +8653,7 @@ test_that("relational mutate(nth(a, 2), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8286,8 +8706,8 @@ test_that("relational mutate(nth(a, 2), .by = g) order-enforcing", { expect_equal( out, data.frame( - a = c(1, 2, 3, 4, 5, 6), - b = c(2, 2, 2, 2, 2, 2), + 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 @@ -8296,13 +8716,201 @@ test_that("relational mutate(nth(a, 2), .by = g) order-enforcing", { dbDisconnect(con, shutdown = TRUE) }) +test_that("relational mutate(a / b) order-enforcing", { + # Autogenerated + con <- dbConnect(duckdb()) + experimental <- FALSE + invisible( + dbExecute( + con, + "CREATE MACRO \"___divide\"(x, y) AS CASE WHEN x = 0 AND y = 0 THEN CAST('NaN' AS double) 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)) + + rel1 <- rel_from_df(con, df1, experimental = experimental) + 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 + } + ) + ) + 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_equal( + 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(c = 0, d = 0, e = c / d) order-enforcing", { + # Autogenerated + con <- dbConnect(duckdb()) + experimental <- FALSE + invisible( + dbExecute( + con, + "CREATE MACRO \"___divide\"(x, y) AS CASE WHEN x = 0 AND y = 0 THEN CAST('NaN' AS double) 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)) + + rel1 <- rel_from_df(con, df1, experimental = experimental) + 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 + } + ) + ) + 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 <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(0, experimental = experimental) + } else { + expr_constant(0) + } + expr_set_alias(tmp_expr, "d") + tmp_expr + } + ) + ) + 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("___divide", list(expr_reference("c"), expr_reference("d"))) + expr_set_alias(tmp_expr, "e") + tmp_expr + } + ) + ) + rel5 <- rel_order( + rel4, + list(expr_reference("a"), expr_reference("b"), expr_reference("g"), expr_reference("c"), expr_reference("d"), expr_reference("e")) + ) + rel5 + out <- rel_to_altrep(rel5) + expect_equal( + 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 = numeric(6), + e = rep(NaN, 6L) + ) + ) + dbDisconnect(con, shutdown = TRUE) +}) + # relocate order-preserving ------------------------------------------------------------ test_that("relational relocate(g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8329,7 +8937,7 @@ test_that("relational relocate(g) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8338,7 +8946,7 @@ test_that("relational relocate(a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8365,7 +8973,7 @@ test_that("relational relocate(a) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8374,7 +8982,7 @@ test_that("relational relocate(g, .before = b) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8401,7 +9009,7 @@ test_that("relational relocate(g, .before = b) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), g = c(1L, 2L, 2L, 3L, 3L, 3L), b = c(2, 2, 2, 2, 2, 2)) + data.frame(a = seq(1, 6, by = 1), g = c(1L, 2L, 2L, 3L, 3L, 3L), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8410,7 +9018,7 @@ test_that("relational relocate(a:b, .after = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8437,7 +9045,7 @@ test_that("relational relocate(a:b, .after = g) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8448,7 +9056,7 @@ test_that("relational relocate(g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8479,7 +9087,7 @@ test_that("relational relocate(g) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8488,7 +9096,7 @@ test_that("relational relocate(a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8519,7 +9127,7 @@ test_that("relational relocate(a) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8528,7 +9136,7 @@ test_that("relational relocate(g, .before = b) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8559,7 +9167,7 @@ test_that("relational relocate(g, .before = b) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), g = c(1L, 2L, 2L, 3L, 3L, 3L), b = c(2, 2, 2, 2, 2, 2)) + data.frame(a = seq(1, 6, by = 1), g = c(1L, 2L, 2L, 3L, 3L, 3L), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8568,7 +9176,7 @@ test_that("relational relocate(a:b, .after = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8599,7 +9207,7 @@ test_that("relational relocate(a:b, .after = g) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8610,7 +9218,7 @@ test_that("relational rename() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8637,7 +9245,7 @@ test_that("relational rename() order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8646,7 +9254,7 @@ test_that("relational rename(c = a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8673,7 +9281,7 @@ test_that("relational rename(c = a) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(c = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(c = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8684,7 +9292,7 @@ test_that("relational rename() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8715,7 +9323,7 @@ test_that("relational rename() order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8724,7 +9332,7 @@ test_that("relational rename(c = a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -8755,7 +9363,7 @@ test_that("relational rename(c = a) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(c = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(c = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8769,14 +9377,14 @@ test_that("relational right_join(join_by(a)) order-preserving", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -8889,7 +9497,7 @@ test_that("relational right_join(join_by(a)) order-preserving", { out <- rel_to_altrep(rel11) expect_equal( out, - data.frame(a = 2:5, b.x = c(2, 2, 2, NA), b.y = c(2, 2, 2, 2)) + data.frame(a = 2:5, b.x = c(2, 2, 2, NA), b.y = rep(2, 4L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8903,14 +9511,14 @@ test_that("relational right_join(join_by(a)) order-enforcing", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -8983,7 +9591,7 @@ test_that("relational right_join(join_by(a)) order-enforcing", { out <- rel_to_altrep(rel9) expect_equal( out, - data.frame(a = 2:5, b.x = c(2, 2, 2, NA), b.y = c(2, 2, 2, 2)) + data.frame(a = 2:5, b.x = c(2, 2, 2, NA), b.y = rep(2, 4L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -8994,22 +9602,24 @@ test_that("relational select(a) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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") - expr_set_alias(tmp_expr, "a") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) ) rel2 out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6)) + data.frame(a = seq(1, 6, by = 1)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9018,7 +9628,7 @@ test_that("relational select(-g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -9040,7 +9650,7 @@ test_that("relational select(-g) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9049,7 +9659,7 @@ test_that("relational select(everything()) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -9076,7 +9686,7 @@ test_that("relational select(everything()) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9087,23 +9697,25 @@ test_that("relational select(a) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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") - expr_set_alias(tmp_expr, "a") - tmp_expr - }) + list( + { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "a") + tmp_expr + } + ) ) rel3 <- rel_order(rel2, list(expr_reference("a"))) rel3 out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6)) + data.frame(a = seq(1, 6, by = 1)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9112,7 +9724,7 @@ test_that("relational select(-g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -9135,7 +9747,7 @@ test_that("relational select(-g) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9144,7 +9756,7 @@ test_that("relational select(everything()) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -9175,7 +9787,7 @@ test_that("relational select(everything()) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9189,14 +9801,14 @@ test_that("relational semi_join(join_by(a)) order-preserving", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -9248,7 +9860,7 @@ test_that("relational semi_join(join_by(a)) order-preserving", { out <- rel_to_altrep(rel8) expect_equal( out, - data.frame(a = 2:4, b = c(2, 2, 2)) + data.frame(a = 2:4, b = rep(2, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9262,14 +9874,14 @@ test_that("relational semi_join(join_by(a)) order-enforcing", { invisible( dbExecute( con, - "CREATE MACRO \"___eq_na_matches_na\"(a, b) AS ((a IS NULL AND b IS NULL) OR (a = b))" + "CREATE MACRO \"___eq_na_matches_na\"(x, y) AS ((x IS NULL AND y IS NULL) OR (x = y))" ) ) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_set_alias(rel1, "lhs") - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel3 <- rel_from_df(con, df2, experimental = experimental) rel4 <- rel_set_alias(rel3, "rhs") @@ -9286,7 +9898,7 @@ test_that("relational semi_join(join_by(a)) order-enforcing", { out <- rel_to_altrep(rel6) expect_equal( out, - data.frame(a = 2:4, b = c(2, 2, 2)) + data.frame(a = 2:4, b = rep(2, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9297,10 +9909,10 @@ test_that("relational setdiff() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_set_diff(rel1, rel2) @@ -9319,10 +9931,10 @@ test_that("relational setdiff() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_set_diff(rel1, rel2) @@ -9342,17 +9954,19 @@ test_that("relational summarise(c = mean(a)) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- expr_function("mean", list(expr_reference("a"))) - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("mean", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) ) rel3 <- rel_distinct(rel2) rel3 @@ -9368,20 +9982,68 @@ test_that("relational summarise(c = mean(a), .by = b) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( + 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 + } + ) + ) + rel3 <- rel_aggregate( + rel2, groups = list(expr_reference("b")), - aggregates = list({ - tmp_expr <- expr_function("mean", list(expr_reference("a"))) - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + 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("mean", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + rel5 <- rel_project( + rel4, + list( + { + tmp_expr <- expr_reference("b") + expr_set_alias(tmp_expr, "b") + tmp_expr + }, + { + tmp_expr <- expr_reference("c") + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) + ) + rel5 + out <- rel_to_altrep(rel5) expect_equal( out, data.frame(b = 2, c = 3.5) @@ -9393,20 +10055,68 @@ test_that("relational summarise(c = mean(a), .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( + 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 + } + ) + ) + rel3 <- rel_aggregate( + rel2, groups = list(expr_reference("g")), - aggregates = list({ - tmp_expr <- expr_function("mean", list(expr_reference("a"))) - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + 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("mean", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + rel5 <- rel_project( + rel4, + list( + { + 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 + } + ) + ) + rel5 + out <- rel_to_altrep(rel5) expect_equal( out, data.frame(g = 1:3, c = c(1, 2.5, 5)) @@ -9418,21 +10128,23 @@ test_that("relational summarise(c = 1) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) + aggregates = list( + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + expr_set_alias(tmp_expr, "c") + tmp_expr } - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + ) ) rel3 <- rel_distinct(rel2) rel3 @@ -9448,27 +10160,75 @@ test_that("relational summarise(c = 1, .by = g) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( + 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 + } + ) + ) + rel3 <- rel_aggregate( + rel2, groups = list(expr_reference("g")), - aggregates = list({ - tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) + aggregates = list( + { + tmp_expr <- expr_function("min", list(expr_reference("___row_number"))) + expr_set_alias(tmp_expr, "___row_number") + tmp_expr + }, + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + expr_set_alias(tmp_expr, "c") + tmp_expr } - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + ) ) - rel2 - out <- rel_to_altrep(rel2) + rel4 <- rel_order(rel3, list(expr_reference("___row_number"))) + rel5 <- rel_project( + rel4, + list( + { + 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 + } + ) + ) + rel5 + out <- rel_to_altrep(rel5) expect_equal( out, - data.frame(g = 1:3, c = c(1, 1, 1)) + data.frame(g = 1:3, c = rep(1, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9479,17 +10239,19 @@ test_that("relational summarise(c = mean(a)) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- expr_function("mean", list(expr_reference("a"))) - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("mean", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) ) rel3 <- rel_distinct(rel2) rel4 <- rel_order(rel3, list(expr_reference("c"))) @@ -9506,17 +10268,19 @@ test_that("relational summarise(c = mean(a), .by = b) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(expr_reference("b")), - aggregates = list({ - tmp_expr <- expr_function("mean", list(expr_reference("a"))) - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("mean", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) ) rel3 <- rel_order(rel2, list(expr_reference("b"), expr_reference("c"))) rel3 @@ -9532,17 +10296,19 @@ test_that("relational summarise(c = mean(a), .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(expr_reference("g")), - aggregates = list({ - tmp_expr <- expr_function("mean", list(expr_reference("a"))) - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("mean", list(expr_reference("a"))) + expr_set_alias(tmp_expr, "c") + tmp_expr + } + ) ) rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("c"))) rel3 @@ -9558,21 +10324,23 @@ test_that("relational summarise(c = 1) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) + aggregates = list( + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + expr_set_alias(tmp_expr, "c") + tmp_expr } - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + ) ) rel3 <- rel_distinct(rel2) rel4 <- rel_order(rel3, list(expr_reference("c"))) @@ -9589,28 +10357,30 @@ test_that("relational summarise(c = 1, .by = g) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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_aggregate( rel1, groups = list(expr_reference("g")), - aggregates = list({ - tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { - expr_constant(1, experimental = experimental) - } else { - expr_constant(1) + aggregates = list( + { + tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) { + expr_constant(1, experimental = experimental) + } else { + expr_constant(1) + } + expr_set_alias(tmp_expr, "c") + tmp_expr } - expr_set_alias(tmp_expr, "c") - tmp_expr - }) + ) ) rel3 <- rel_order(rel2, list(expr_reference("g"), expr_reference("c"))) rel3 out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(g = 1:3, c = c(1, 1, 1)) + data.frame(g = 1:3, c = rep(1, 3L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9621,10 +10391,10 @@ test_that("relational symdiff() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_set_symdiff(rel1, rel2) @@ -9643,10 +10413,10 @@ test_that("relational symdiff() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_set_symdiff(rel1, rel2) @@ -9666,18 +10436,20 @@ test_that("relational tally() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) rel3 <- rel_distinct(rel2) rel3 @@ -9695,18 +10467,20 @@ test_that("relational tally() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"n\"() AS (COUNT(*))")) - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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)) rel1 <- rel_from_df(con, df1, experimental = experimental) rel2 <- rel_aggregate( rel1, groups = list(), - aggregates = list({ - tmp_expr <- expr_function("n", list()) - expr_set_alias(tmp_expr, "n") - tmp_expr - }) + aggregates = list( + { + tmp_expr <- expr_function("n", list()) + expr_set_alias(tmp_expr, "n") + tmp_expr + } + ) ) rel3 <- rel_distinct(rel2) rel4 <- rel_order(rel3, list(expr_reference("n"))) @@ -9725,7 +10499,7 @@ test_that("relational transmute(c = a + 1) order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -9752,7 +10526,33 @@ test_that("relational transmute(c = a + 1) order-preserving", { out <- rel_to_altrep(rel2) expect_equal( out, - data.frame(c = c(2, 3, 4, 5, 6, 7)) + data.frame(c = seq(2, 7, by = 1)) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational transmute(row = a) order-preserving", { + # 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( + row = { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "row") + tmp_expr + } + ) + ) + rel2 + out <- rel_to_altrep(rel2) + expect_equal( + out, + data.frame(row = seq(1, 6, by = 1)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9763,7 +10563,7 @@ test_that("relational transmute(c = a + 1) order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = c(1, 2, 3, 4, 5, 6), b = c(2, 2, 2, 2, 2, 2), g = c(1L, 2L, 2L, 3L, 3L, 3L)) + 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( @@ -9791,7 +10591,34 @@ test_that("relational transmute(c = a + 1) order-enforcing", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(c = c(2, 3, 4, 5, 6, 7)) + data.frame(c = seq(2, 7, by = 1)) + ) + dbDisconnect(con, shutdown = TRUE) +}) + +test_that("relational transmute(row = 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( + row = { + tmp_expr <- expr_reference("a") + expr_set_alias(tmp_expr, "row") + tmp_expr + } + ) + ) + rel3 <- rel_order(rel2, list(expr_reference("row"))) + rel3 + out <- rel_to_altrep(rel3) + expect_equal( + out, + data.frame(row = seq(1, 6, by = 1)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9802,11 +10629,11 @@ test_that("relational union() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - invisible(dbExecute(con, "CREATE MACRO \"==\"(a, b) AS a = b")) - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + invisible(dbExecute(con, "CREATE MACRO \"==\"(x, y) AS x = y")) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_union_all(rel1, rel2) @@ -9904,7 +10731,7 @@ test_that("relational union() order-preserving", { out <- rel_to_altrep(rel8) expect_equal( out, - data.frame(a = 1:5, b = c(2, 2, 2, 2, 2)) + data.frame(a = 1:5, b = rep(2, 5L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9915,10 +10742,10 @@ test_that("relational union() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_union_all(rel1, rel2) @@ -9928,7 +10755,7 @@ test_that("relational union() order-enforcing", { out <- rel_to_altrep(rel5) expect_equal( out, - data.frame(a = 1:5, b = c(2, 2, 2, 2, 2)) + data.frame(a = 1:5, b = rep(2, 5L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9939,10 +10766,10 @@ test_that("relational union_all() order-preserving", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_union_all(rel1, rel2) @@ -9950,7 +10777,7 @@ test_that("relational union_all() order-preserving", { out <- rel_to_altrep(rel3) expect_equal( out, - data.frame(a = c(1L, 2L, 3L, 4L, 2L, 3L, 4L, 5L), b = c(2, 2, 2, 2, 2, 2, 2, 2)) + data.frame(a = c(1L, 2L, 3L, 4L, 2L, 3L, 4L, 5L), b = rep(2, 8L)) ) dbDisconnect(con, shutdown = TRUE) }) @@ -9961,10 +10788,10 @@ test_that("relational union_all() order-enforcing", { # Autogenerated con <- dbConnect(duckdb()) experimental <- FALSE - df1 <- data.frame(a = 1:4, b = c(2, 2, 2, 2)) + df1 <- data.frame(a = 1:4, b = rep(2, 4L)) rel1 <- rel_from_df(con, df1, experimental = experimental) - df2 <- data.frame(a = 2:5, b = c(2, 2, 2, 2)) + df2 <- data.frame(a = 2:5, b = rep(2, 4L)) rel2 <- rel_from_df(con, df2, experimental = experimental) rel3 <- rel_union_all(rel1, rel2) @@ -9973,7 +10800,7 @@ test_that("relational union_all() order-enforcing", { out <- rel_to_altrep(rel4) expect_equal( out, - data.frame(a = c(1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L), b = c(2, 2, 2, 2, 2, 2, 2, 2)) + data.frame(a = c(1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L), b = rep(2, 8L)) ) dbDisconnect(con, shutdown = TRUE) })