# Generated by duckplyr's 05-duckdb-tests.R, do not edit by hand
# anti_join order-preserving -----------------------------------------------------------
test_that("relational anti_join(join_by(a)) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
df1 <- data.frame(a = 1:4, b = rep(2, 4L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_set_alias(rel1, "lhs")
df2 <- data.frame(a = 2:5, b = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- 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_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "___row_number_x")
tmp_expr
}
)
)
rel6 <- rel_join(
rel5,
rel4,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a", rel5), expr_reference("a", rel4)))
),
"anti"
)
rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5)))
rel8 <- rel_project(
rel7,
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
}
)
)
rel8
out <- rel_to_altrep(rel8)
expect_equal(
out,
data.frame(a = 1L, b = 2)
)
dbDisconnect(con, shutdown = TRUE)
})
# anti_join order-enforcing ------------------------------------------------------------
test_that("relational anti_join(join_by(a)) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
df1 <- data.frame(a = 1:4, b = rep(2, 4L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_set_alias(rel1, "lhs")
df2 <- data.frame(a = 2:5, b = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_join(
rel2,
rel4,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a", rel2), expr_reference("a", rel4)))
),
"anti"
)
rel6 <- rel_order(rel5, list(expr_reference("a"), expr_reference("b")))
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(a = 1L, b = 2)
)
dbDisconnect(con, shutdown = TRUE)
})
# arrange order-preserving -------------------------------------------------------------
test_that("relational arrange() 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)
rel1
out <- rel_to_altrep(rel1)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(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(
{
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_order(rel2, list(expr_reference("a"), expr_reference("___row_number")))
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
}
)
)
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(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_order(rel2, list(expr_reference("g"), expr_reference("___row_number")))
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
}
)
)
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(g, 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(
{
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_order(
rel2,
list(expr_reference("g"), expr_reference("a"), expr_reference("___row_number"))
)
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
}
)
)
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(a, 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_order(
rel2,
list(expr_reference("a"), expr_reference("g"), expr_reference("___row_number"))
)
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
}
)
)
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# arrange order-enforcing --------------------------------------------------------------
test_that("relational arrange() 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_from_df(con, df1, experimental = experimental)
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
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))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(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_order(rel1, list(expr_reference("a")))
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
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))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_order(rel1, list(expr_reference("g")))
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
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))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(g, 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_order(rel1, list(expr_reference("g"), expr_reference("a")))
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
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))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational arrange(a, g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_order(rel1, list(expr_reference("a"), expr_reference("g")))
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
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))
)
dbDisconnect(con, shutdown = TRUE)
})
# count order-preserving ---------------------------------------------------------------
test_that("relational count() order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
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
}
)
)
rel2
out <- rel_to_altrep(rel2)
expect_equal(
out,
data.frame(n = 6L)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(a) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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(
{
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 = seq(1, 6, by = 1), n = rep(1L, 6L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(b) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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(
{
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)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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(
{
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)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(g, a) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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
}
)
)
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), n = rep(1L, 6L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(b, g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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
}
)
)
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(b = rep(2, 3L), g = 1:3, n = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
# count order-enforcing ----------------------------------------------------------------
test_that("relational count() order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
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
}
)
)
rel3 <- rel_order(rel2, list(expr_reference("n")))
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(n = 6L)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(a) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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(
{
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 = seq(1, 6, by = 1), n = rep(1L, 6L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(b) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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(
{
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)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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(
{
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)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(g, a) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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"))
)
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(g = c(1L, 2L, 2L, 3L, 3L, 3L), a = seq(1, 6, by = 1), n = rep(1L, 6L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational count(b, g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "n"() AS CAST(COUNT(*) AS int32)'))
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_aggregate(
rel1,
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"))
)
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(b = rep(2, 3L), g = 1:3, n = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
# distinct order-preserving ------------------------------------------------------------
test_that("relational distinct() order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
a = {
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
},
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
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
},
{
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
}
)
)
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(a) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
a = {
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
}
)
)
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(a, b) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
a = {
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
},
b = {
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
}
)
)
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(b, b) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
b = {
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
}
)
)
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(b = 2)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
}
)
)
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- 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_x")
tmp_expr
},
{
tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_y")
tmp_expr
}
)
)
rel4 <- 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 <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_x")
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_y")
tmp_expr
}
)
)
rel5 <- rel_union_all(rel3, rel4)
rel6 <- rel_order(
rel5,
list(expr_reference("___row_number_x"), expr_reference("___row_number_y"))
)
rel7 <- rel_project(
rel6,
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
}
)
)
rel8 <- rel_project(
rel7,
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
}
)
)
rel9 <- rel_project(
rel8,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel10 <- rel_filter(
rel9,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
rel11 <- rel_order(rel10, list(expr_reference("___row_number")))
rel12 <- rel_project(
rel11,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel12
out <- rel_to_altrep(rel12)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- 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_x")
tmp_expr
},
{
tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_y")
tmp_expr
}
)
)
rel4 <- 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 <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_x")
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_y")
tmp_expr
}
)
)
rel5 <- rel_union_all(rel3, rel4)
rel6 <- rel_order(
rel5,
list(expr_reference("___row_number_x"), expr_reference("___row_number_y"))
)
rel7 <- rel_project(
rel6,
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
}
)
)
rel8 <- rel_project(
rel7,
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
}
)
)
rel9 <- rel_project(
rel8,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel10 <- rel_filter(
rel9,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
rel11 <- rel_order(rel10, list(expr_reference("___row_number")))
rel12 <- rel_project(
rel11,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel12
out <- rel_to_altrep(rel12)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- 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_x")
tmp_expr
},
{
tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_y")
tmp_expr
}
)
)
rel4 <- 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 <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_x")
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_y")
tmp_expr
}
)
)
rel5 <- rel_union_all(rel3, rel4)
rel6 <- rel_order(
rel5,
list(expr_reference("___row_number_x"), expr_reference("___row_number_y"))
)
rel7 <- rel_project(
rel6,
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
}
)
)
rel8 <- rel_project(
rel7,
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
}
)
)
rel9 <- rel_project(
rel8,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel10 <- rel_filter(
rel9,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
rel11 <- rel_order(rel10, list(expr_reference("___row_number")))
rel12 <- rel_project(
rel11,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel12
out <- rel_to_altrep(rel12)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- 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_x")
tmp_expr
},
{
tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_y")
tmp_expr
}
)
)
rel4 <- 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 <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_x")
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_y")
tmp_expr
}
)
)
rel5 <- rel_union_all(rel3, rel4)
rel6 <- rel_order(
rel5,
list(expr_reference("___row_number_x"), expr_reference("___row_number_y"))
)
rel7 <- rel_project(
rel6,
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
}
)
)
rel8 <- rel_project(
rel7,
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
}
)
)
rel9 <- rel_project(
rel8,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel10 <- rel_filter(
rel9,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
rel11 <- rel_order(rel10, list(expr_reference("___row_number")))
rel12 <- rel_project(
rel11,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel12
out <- rel_to_altrep(rel12)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct(g) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- 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_x")
tmp_expr
},
{
tmp_expr <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_y")
tmp_expr
}
)
)
rel4 <- 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 <- if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(NA_integer_, experimental = experimental)
} else {
expr_constant(NA_integer_)
}
expr_set_alias(tmp_expr, "___row_number_x")
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_y")
tmp_expr
}
)
)
rel5 <- rel_union_all(rel3, rel4)
rel6 <- rel_order(
rel5,
list(expr_reference("___row_number_x"), expr_reference("___row_number_y"))
)
rel7 <- rel_project(
rel6,
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
}
)
)
rel8 <- rel_project(
rel7,
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
}
)
)
rel9 <- rel_project(
rel8,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel10 <- rel_filter(
rel9,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
rel11 <- rel_order(rel10, list(expr_reference("___row_number")))
rel12 <- rel_project(
rel11,
list(
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel12
out <- rel_to_altrep(rel12)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(g, .keep_all = TRUE) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
},
{
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
}
)
)
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(a = c(1, 2, 4), b = rep(2, 3L), g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
# distinct order-enforcing -------------------------------------------------------------
test_that("relational distinct() 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_distinct(rel1)
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
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))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(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(
a = {
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
}
)
)
rel3 <- rel_distinct(rel2)
rel4 <- rel_order(rel3, list(expr_reference("a")))
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(a, b) 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(
a = {
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
},
b = {
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
}
)
)
rel3 <- rel_distinct(rel2)
rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b")))
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(b, b) 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(
b = {
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
}
)
)
rel3 <- rel_distinct(rel2)
rel4 <- rel_order(rel3, list(expr_reference("b")))
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(b = 2)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
rel2 <- rel_project(
rel1,
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel3 <- rel_distinct(rel2)
rel4 <- rel_order(rel3, list(expr_reference("g")))
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 3, g = 2L)) %>% distinct(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
df2 <- data.frame(a = 1L, b = 3, g = 2L)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- rel_union_all(rel1, rel2)
rel4 <- rel_project(
rel3,
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel5 <- rel_distinct(rel4)
rel6 <- rel_order(rel5, list(expr_reference("g")))
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 4, g = 2L)) %>% distinct(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
df2 <- data.frame(a = 1L, b = 4, g = 2L)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- rel_union_all(rel1, rel2)
rel4 <- rel_project(
rel3,
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel5 <- rel_distinct(rel4)
rel6 <- rel_order(rel5, list(expr_reference("g")))
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 5, g = 2L)) %>% distinct(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
df2 <- data.frame(a = 1L, b = 5, g = 2L)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- rel_union_all(rel1, rel2)
rel4 <- rel_project(
rel3,
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel5 <- rel_distinct(rel4)
rel6 <- rel_order(rel5, list(expr_reference("g")))
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 6, g = 2L)) %>% distinct(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
df2 <- data.frame(a = 1L, b = 6, g = 2L)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- rel_union_all(rel1, rel2)
rel4 <- rel_project(
rel3,
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel5 <- rel_distinct(rel4)
rel6 <- rel_order(rel5, list(expr_reference("g")))
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational union_all(data.frame(a = 1L, b = 7, g = 2L)) %>% distinct(g) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
df1 <- data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
rel1 <- rel_from_df(con, df1, experimental = experimental)
df2 <- data.frame(a = 1L, b = 7, g = 2L)
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- rel_union_all(rel1, rel2)
rel4 <- rel_project(
rel3,
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
)
)
rel5 <- rel_distinct(rel4)
rel6 <- rel_order(rel5, list(expr_reference("g")))
rel6
out <- rel_to_altrep(rel6)
expect_equal(
out,
data.frame(g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational distinct(g, .keep_all = TRUE) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
g = {
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel4 <- rel_filter(
rel3,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
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
},
{
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
}
)
)
rel7 <- rel_order(
rel6,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
rel7
out <- rel_to_altrep(rel7)
expect_equal(
out,
data.frame(a = c(1, 2, 4), b = rep(2, 3L), g = 1:3)
)
dbDisconnect(con, shutdown = TRUE)
})
# filter order-preserving --------------------------------------------------------------
test_that("relational filter(a == 1) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
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_filter(
rel2,
list(
expr_function(
"==",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1, experimental = experimental)
} else {
expr_constant(1)
}
)
)
)
)
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
}
)
)
rel5
out <- rel_to_altrep(rel5)
expect_equal(
out,
data.frame(a = 1, b = 2, g = 1L)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational filter(a %in% 2:3, g == 2) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)'))
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(
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_filter(
rel2,
list(
expr_function(
"|",
list(
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2L, experimental = experimental)
} else {
expr_constant(2L)
},
expr_reference("a")
)
),
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(3L, experimental = experimental)
} else {
expr_constant(3L)
},
expr_reference("a")
)
)
)
),
expr_function(
"==",
list(
expr_reference("g"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
)
)
)
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
}
)
)
rel5
out <- rel_to_altrep(rel5)
expect_equal(
out,
data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational filter(a %in% 2:3 & g == 2) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
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 "=="(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(
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_filter(
rel2,
list(
expr_function(
"&",
list(
expr_function(
"|",
list(
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2L, experimental = experimental)
} else {
expr_constant(2L)
},
expr_reference("a")
)
),
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(3L, experimental = experimental)
} else {
expr_constant(3L)
},
expr_reference("a")
)
)
)
),
expr_function(
"==",
list(
expr_reference("g"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
)
)
)
)
)
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
}
)
)
rel5
out <- rel_to_altrep(rel5)
expect_equal(
out,
data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational filter(a != 2 | g != 2) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)'))
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(
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_filter(
rel2,
list(
expr_function(
"|",
list(
expr_function(
"!=",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
),
expr_function(
"!=",
list(
expr_reference("g"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
)
)
)
)
)
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
}
)
)
rel5
out <- rel_to_altrep(rel5)
expect_equal(
out,
data.frame(a = c(1, 3, 4, 5, 6), b = rep(2, 5L), g = c(1L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# filter order-enforcing ---------------------------------------------------------------
test_that("relational filter(a == 1) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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(
rel1,
list(
expr_function(
"==",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1, experimental = experimental)
} else {
expr_constant(1)
}
)
)
)
)
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(a = 1, b = 2, g = 1L)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational filter(a %in% 2:3, g == 2) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)'))
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(
rel1,
list(
expr_function(
"|",
list(
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2L, experimental = experimental)
} else {
expr_constant(2L)
},
expr_reference("a")
)
),
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(3L, experimental = experimental)
} else {
expr_constant(3L)
},
expr_reference("a")
)
)
)
),
expr_function(
"==",
list(
expr_reference("g"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
)
)
)
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational filter(a %in% 2:3 & g == 2) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
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 "=="(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(
rel1,
list(
expr_function(
"&",
list(
expr_function(
"|",
list(
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2L, experimental = experimental)
} else {
expr_constant(2L)
},
expr_reference("a")
)
),
expr_function(
"==",
list(
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(3L, experimental = experimental)
} else {
expr_constant(3L)
},
expr_reference("a")
)
)
)
),
expr_function(
"==",
list(
expr_reference("g"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
)
)
)
)
)
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(a = c(2, 3), b = c(2, 2), g = c(2L, 2L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational filter(a != 2 | g != 2) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(dbExecute(con, 'CREATE MACRO "|"(x, y) AS (x OR y)'))
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(
rel1,
list(
expr_function(
"|",
list(
expr_function(
"!=",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
),
expr_function(
"!=",
list(
expr_reference("g"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
}
)
)
)
)
)
)
rel3 <- rel_order(
rel2,
list(expr_reference("a"), expr_reference("b"), expr_reference("g"))
)
rel3
out <- rel_to_altrep(rel3)
expect_equal(
out,
data.frame(a = c(1, 3, 4, 5, 6), b = rep(2, 5L), g = c(1L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# full_join order-preserving -----------------------------------------------------------
test_that("relational full_join(join_by(a)) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "___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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_project(
rel2,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_x")
tmp_expr
}
)
)
rel6 <- rel_project(
rel4,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_y")
tmp_expr
}
)
)
rel7 <- rel_project(
rel5,
list(
{
tmp_expr <- expr_reference("a_x")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b_x")
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_x")
tmp_expr
}
)
)
rel8 <- rel_project(
rel6,
list(
{
tmp_expr <- expr_reference("a_y")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b_y")
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_y")
tmp_expr
}
)
)
rel9 <- rel_join(
rel7,
rel8,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)))
),
"outer"
)
rel10 <- rel_order(
rel9,
list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8))
)
rel11 <- rel_project(
rel10,
list(
{
tmp_expr <- expr_function("___coalesce", list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)))
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b.x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b.y")
tmp_expr
}
)
)
rel11
out <- rel_to_altrep(rel11)
expect_equal(
out,
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)
})
# full_join order-enforcing ------------------------------------------------------------
test_that("relational full_join(join_by(a)) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "___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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_project(
rel2,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_x")
tmp_expr
}
)
)
rel6 <- rel_project(
rel4,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_y")
tmp_expr
}
)
)
rel7 <- rel_join(
rel5,
rel6,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)))
),
"outer"
)
rel8 <- rel_project(
rel7,
list(
{
tmp_expr <- expr_function("___coalesce", list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)))
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b.x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b.y")
tmp_expr
}
)
)
rel9 <- rel_order(
rel8,
list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y"))
)
rel9
out <- rel_to_altrep(rel9)
expect_equal(
out,
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)
})
# inner_join order-preserving ----------------------------------------------------------
test_that("relational inner_join(join_by(a)) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "___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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_project(
rel2,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_x")
tmp_expr
}
)
)
rel6 <- rel_project(
rel4,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_y")
tmp_expr
}
)
)
rel7 <- rel_project(
rel5,
list(
{
tmp_expr <- expr_reference("a_x")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b_x")
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_x")
tmp_expr
}
)
)
rel8 <- rel_project(
rel6,
list(
{
tmp_expr <- expr_reference("a_y")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b_y")
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_y")
tmp_expr
}
)
)
rel9 <- rel_join(
rel7,
rel8,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)))
),
"inner"
)
rel10 <- rel_order(
rel9,
list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8))
)
rel11 <- rel_project(
rel10,
list(
{
tmp_expr <- expr_function("___coalesce", list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)))
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b.x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b.y")
tmp_expr
}
)
)
rel11
out <- rel_to_altrep(rel11)
expect_equal(
out,
data.frame(a = 2:4, b.x = rep(2, 3L), b.y = rep(2, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# inner_join order-enforcing -----------------------------------------------------------
test_that("relational inner_join(join_by(a)) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "___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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_project(
rel2,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_x")
tmp_expr
}
)
)
rel6 <- rel_project(
rel4,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_y")
tmp_expr
}
)
)
rel7 <- rel_join(
rel5,
rel6,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)))
),
"inner"
)
rel8 <- rel_project(
rel7,
list(
{
tmp_expr <- expr_function("___coalesce", list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)))
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b.x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b.y")
tmp_expr
}
)
)
rel9 <- rel_order(
rel8,
list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y"))
)
rel9
out <- rel_to_altrep(rel9)
expect_equal(
out,
data.frame(a = 2:4, b.x = rep(2, 3L), b.y = rep(2, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# intersect order-preserving -----------------------------------------------------------
test_that("relational intersect() order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "=="(x, y) AS x = y'))
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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- 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_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "___row_number_x")
tmp_expr
}
)
)
rel6 <- rel_join(
rel5,
rel4,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a", rel5), expr_reference("a", rel4))),
expr_function("___eq_na_matches_na", list(expr_reference("b", rel5), expr_reference("b", rel4)))
),
"semi"
)
rel7 <- rel_order(rel6, list(expr_reference("___row_number_x", rel5)))
rel8 <- rel_project(
rel7,
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
}
)
)
rel9 <- rel_project(
rel8,
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_window(expr_function("row_number", list()), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "___row_number")
tmp_expr
}
)
)
rel10 <- rel_project(
rel9,
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
},
expr_reference("___row_number"),
{
tmp_expr <- expr_window(
expr_function("row_number", list()),
list(
a = {
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
},
b = {
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
}
),
list(expr_reference("___row_number")),
offset_expr = NULL,
default_expr = NULL
)
expr_set_alias(tmp_expr, "___row_number_by")
tmp_expr
}
)
)
rel11 <- rel_filter(
rel10,
list(
expr_function(
"==",
list(
expr_reference("___row_number_by"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
}
)
)
)
)
rel12 <- rel_order(rel11, list(expr_reference("___row_number")))
rel13 <- rel_project(
rel12,
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
}
)
)
rel13
out <- rel_to_altrep(rel13)
expect_equal(
out,
data.frame(a = 2:4, b = rep(2, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# intersect order-enforcing ------------------------------------------------------------
test_that("relational intersect() order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
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 = rep(2, 4L))
rel2 <- rel_from_df(con, df2, experimental = experimental)
rel3 <- rel_set_intersect(rel1, rel2)
rel4 <- rel_order(rel3, list(expr_reference("a"), expr_reference("b")))
rel4
out <- rel_to_altrep(rel4)
expect_equal(
out,
data.frame(a = 2:4, b = rep(2, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
# left_join order-preserving -----------------------------------------------------------
test_that("relational left_join(join_by(a)) order-preserving", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "___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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_project(
rel2,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_x")
tmp_expr
}
)
)
rel6 <- rel_project(
rel4,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_y")
tmp_expr
}
)
)
rel7 <- rel_project(
rel5,
list(
{
tmp_expr <- expr_reference("a_x")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b_x")
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_x")
tmp_expr
}
)
)
rel8 <- rel_project(
rel6,
list(
{
tmp_expr <- expr_reference("a_y")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b_y")
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_y")
tmp_expr
}
)
)
rel9 <- rel_join(
rel7,
rel8,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)))
),
"left"
)
rel10 <- rel_order(
rel9,
list(expr_reference("___row_number_x", rel7), expr_reference("___row_number_y", rel8))
)
rel11 <- rel_project(
rel10,
list(
{
tmp_expr <- expr_function("___coalesce", list(expr_reference("a_x", rel7), expr_reference("a_y", rel8)))
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b.x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b.y")
tmp_expr
}
)
)
rel11
out <- rel_to_altrep(rel11)
expect_equal(
out,
data.frame(a = 1:4, b.x = rep(2, 4L), b.y = c(NA, 2, 2, 2))
)
dbDisconnect(con, shutdown = TRUE)
})
# left_join order-enforcing ------------------------------------------------------------
test_that("relational left_join(join_by(a)) order-enforcing", {
# Autogenerated
con <- dbConnect(duckdb())
experimental <- FALSE
invisible(
dbExecute(con, 'CREATE MACRO "___eq_na_matches_na"(x, y) AS (x IS NOT DISTINCT FROM y)')
)
invisible(dbExecute(con, 'CREATE MACRO "___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 = rep(2, 4L))
rel3 <- rel_from_df(con, df2, experimental = experimental)
rel4 <- rel_set_alias(rel3, "rhs")
rel5 <- rel_project(
rel2,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_x")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_x")
tmp_expr
}
)
)
rel6 <- rel_project(
rel4,
list(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a_y")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b_y")
tmp_expr
}
)
)
rel7 <- rel_join(
rel5,
rel6,
list(
expr_function("___eq_na_matches_na", list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)))
),
"left"
)
rel8 <- rel_project(
rel7,
list(
{
tmp_expr <- expr_function("___coalesce", list(expr_reference("a_x", rel5), expr_reference("a_y", rel6)))
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b_x")
expr_set_alias(tmp_expr, "b.x")
tmp_expr
},
{
tmp_expr <- expr_reference("b_y")
expr_set_alias(tmp_expr, "b.y")
tmp_expr
}
)
)
rel9 <- rel_order(
rel8,
list(expr_reference("a"), expr_reference("b.x"), expr_reference("b.y"))
)
rel9
out <- rel_to_altrep(rel9)
expect_equal(
out,
data.frame(a = 1:4, b.x = rep(2, 4L), b.y = c(NA, 2, 2, 2))
)
dbDisconnect(con, shutdown = TRUE)
})
# mutate order-preserving --------------------------------------------------------------
test_that("relational mutate() 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)
rel1
out <- rel_to_altrep(rel1)
expect_equal(
out,
data.frame(a = seq(1, 6, by = 1), b = rep(2, 6L), g = c(1L, 2L, 2L, 3L, 3L, 3L))
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(a + 1) order-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_function(
"+",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1, experimental = experimental)
} else {
expr_constant(1)
}
)
)
expr_set_alias(tmp_expr, "a + 1")
tmp_expr
}
)
)
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),
`a + 1` = seq(2, 7, by = 1),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(a + 1, .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_function(
"+",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1, experimental = experimental)
} else {
expr_constant(1)
}
)
)
expr_set_alias(tmp_expr, "a + 1")
tmp_expr
}
)
)
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("a + 1")
expr_set_alias(tmp_expr, "a + 1")
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),
`a + 1` = seq(2, 7, by = 1),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(c = a + 1) 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_function(
"+",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1, experimental = experimental)
} else {
expr_constant(1)
}
)
)
expr_set_alias(tmp_expr, "c")
tmp_expr
}
)
)
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),
c = seq(2, 7, by = 1)
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(`if` = a + 1) 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_function(
"+",
list(
expr_reference("a"),
if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1, experimental = experimental)
} else {
expr_constant(1)
}
)
)
expr_set_alias(tmp_expr, "if")
tmp_expr
}
)
)
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),
`if` = seq(2, 7, by = 1),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(sum(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(
{
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("sum", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "sum(a)")
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),
`sum(a)` = rep(21, 6L),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(sum(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("sum", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "sum(a)")
tmp_expr
}
)
)
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("sum(a)")
expr_set_alias(tmp_expr, "sum(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),
`sum(a)` = c(1, 5, 5, 15, 15, 15),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(mean(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(
{
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("mean", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "mean(a)")
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),
`mean(a)` = rep(3.5, 6L),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(mean(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("mean", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "mean(a)")
tmp_expr
}
)
)
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("mean(a)")
expr_set_alias(tmp_expr, "mean(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),
`mean(a)` = c(1, 2.5, 2.5, 5, 5, 5),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(sd(a)) order-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("stddev", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "sd(a)")
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),
`sd(a)` = rep(0x1.deeea11683f49p+0, 6L),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(sd(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("stddev", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "sd(a)")
tmp_expr
}
)
)
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("sd(a)")
expr_set_alias(tmp_expr, "sd(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),
`sd(a)` = c(NA, 0.7071067811865476, 0.7071067811865476, 1, 1, 1),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(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(
{
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("lag", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lag(a)")
tmp_expr
}
)
)
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),
`lag(a)` = c(NA, 1, 2, 3, 4, 5),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(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("lag", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lag(a)")
tmp_expr
}
)
)
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("lag(a)")
expr_set_alias(tmp_expr, "lag(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),
`lag(a)` = c(NA, NA, 2, NA, 4, 5),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(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(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
},
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
{
tmp_expr <- expr_window(
expr_function("lead", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lead(a)")
tmp_expr
}
)
)
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),
`lead(a)` = c(2, 3, 4, 5, 6, NA),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(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("lead", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lead(a)")
tmp_expr
}
)
)
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("lead(a)")
expr_set_alias(tmp_expr, "lead(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),
`lead(a)` = c(NA, 3, NA, 5, 6, NA),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(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("lag", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lag(a, 2)")
tmp_expr
}
)
)
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),
`lag(a, 2)` = c(NA, NA, 1, 2, 3, 4),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(a, 2), .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("lag", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lag(a, 2)")
tmp_expr
}
)
)
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("lag(a, 2)")
expr_set_alias(tmp_expr, "lag(a, 2)")
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),
`lag(a, 2)` = rep(c(NA, 4), c(5L, 1L)),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(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("lead", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lead(a, 2)")
tmp_expr
}
)
)
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),
`lead(a, 2)` = c(3, 4, 5, 6, NA, NA),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(a, 2), .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("lead", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(2, experimental = experimental)
} else {
expr_constant(2)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lead(a, 2)")
tmp_expr
}
)
)
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("lead(a, 2)")
expr_set_alias(tmp_expr, "lead(a, 2)")
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),
`lead(a, 2)` = c(NA, NA, NA, 6, NA, NA),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(a, 4)) 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("lag", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(4, experimental = experimental)
} else {
expr_constant(4)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lag(a, 4)")
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),
`lag(a, 4)` = c(NA, NA, NA, NA, 1, 2),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(a, 4), .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("lag", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(4, experimental = experimental)
} else {
expr_constant(4)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lag(a, 4)")
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("lag(a, 4)")
expr_set_alias(tmp_expr, "lag(a, 4)")
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),
`lag(a, 4)` = rep(NA_real_, 6L),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(a, 4)) 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("lead", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(4, experimental = experimental)
} else {
expr_constant(4)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lead(a, 4)")
tmp_expr
}
)
)
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),
`lead(a, 4)` = c(5, 6, NA, NA, NA, NA),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(a, 4), .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("lead", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(4, experimental = experimental)
} else {
expr_constant(4)
},
default_expr = NULL
)
expr_set_alias(tmp_expr, "lead(a, 4)")
tmp_expr
}
)
)
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("lead(a, 4)")
expr_set_alias(tmp_expr, "lead(a, 4)")
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),
`lead(a, 4)` = rep(NA_real_, 6L),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(a, default = 0)) 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("lag", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(0, experimental = experimental)
} else {
expr_constant(0)
}
)
expr_set_alias(tmp_expr, "lag(a, default = 0)")
tmp_expr
}
)
)
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),
`lag(a, default = 0)` = seq(0, 5, by = 1),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lag(a, default = 0), .by = g) order-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("lag", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(0, experimental = experimental)
} else {
expr_constant(0)
}
)
expr_set_alias(tmp_expr, "lag(a, default = 0)")
tmp_expr
}
)
)
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("lag(a, default = 0)")
expr_set_alias(tmp_expr, "lag(a, default = 0)")
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),
`lag(a, default = 0)` = c(0, 0, 2, 0, 4, 5),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(a, default = 1000)) order-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("lead", list(x = expr_reference("a"))),
list(),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1000, experimental = experimental)
} else {
expr_constant(1000)
}
)
expr_set_alias(tmp_expr, "lead(a, default = 1000)")
tmp_expr
}
)
)
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),
`lead(a, default = 1000)` = c(2, 3, 4, 5, 6, 1000),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(lead(a, default = 1000), .by = g) order-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("lead", list(x = expr_reference("a"))),
list(expr_reference("g")),
list(),
offset_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1L, experimental = experimental)
} else {
expr_constant(1L)
},
default_expr = if ("experimental" %in% names(formals(expr_constant))) {
expr_constant(1000, experimental = experimental)
} else {
expr_constant(1000)
}
)
expr_set_alias(tmp_expr, "lead(a, default = 1000)")
tmp_expr
}
)
)
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("lead(a, default = 1000)")
expr_set_alias(tmp_expr, "lead(a, default = 1000)")
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),
`lead(a, default = 1000)` = c(1000, 3, 1000, 5, 6, 1000),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(min(a)) order-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("min", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "min(a)")
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),
`min(a)` = rep(1, 6L),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(min(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("min", list(expr_reference("a"))), list(expr_reference("g")), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "min(a)")
tmp_expr
}
)
)
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("min(a)")
expr_set_alias(tmp_expr, "min(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),
`min(a)` = c(1, 2, 2, 4, 4, 4),
check.names = FALSE
)
)
dbDisconnect(con, shutdown = TRUE)
})
test_that("relational mutate(max(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(
{
tmp_expr <- expr_reference("a")
expr_set_alias(tmp_expr, "a")
tmp_expr
},
{
tmp_expr <- expr_reference("b")
expr_set_alias(tmp_expr, "b")
tmp_expr
},
{
tmp_expr <- expr_reference("g")
expr_set_alias(tmp_expr, "g")
tmp_expr
},
{
tmp_expr <- expr_window(expr_function("max", list(expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL)
expr_set_alias(tmp_expr, "max(a)")
tmp_expr
}
)
)
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),
`max(a)` = rep(6, 6L),
check