-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine select
inline criteria to keep arrange
d computed columns
#1446
Changes from all commits
ddf2a79
5867a59
df29760
e3dc35e
60938d0
33cbde7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,31 @@ test_that("select after distinct produces subquery", { | |
expect_true(lq$x$distinct) | ||
}) | ||
|
||
test_that("select after arrange produces subquery, if needed", { | ||
lf <- lazy_frame(x = 1) | ||
|
||
# shouldn't inline | ||
out <- lf %>% mutate(z = 2) %>% arrange(x, z) %>% select(x) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this is testing the right thing because when I run it, I see:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe that is the expected behaviour? But definitely worth a snapshot test, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that is expected. I've re-added the snapshot I removed in my prior commit. |
||
# should inline | ||
out2 <- lf %>% mutate(z = 2) %>% arrange(x, z) %>% select(x, z) | ||
|
||
inner_query <- out$lazy_query$x | ||
expect_s3_class(inner_query, "lazy_select_query") | ||
expect_equal(inner_query$order_by, list(quo(x), quo(z)), ignore_formula_env = TRUE) | ||
expect_equal( | ||
op_vars(inner_query), | ||
c("x", "z") | ||
) | ||
expect_equal(op_vars(out$lazy_query), "x") | ||
|
||
# order vars in a subquery are dropped | ||
expect_equal( | ||
inner_query[setdiff(names(inner_query), "order_vars")], | ||
out2$lazy_query[setdiff(names(out2$lazy_query), "order_vars")] | ||
) | ||
}) | ||
|
||
|
||
test_that("rename/relocate after distinct is inlined #1141", { | ||
lf <- lazy_frame(x = 1, y = 1:2) | ||
expect_snapshot({ | ||
|
@@ -284,6 +309,33 @@ test_that("where() isn't suppored", { | |
}) | ||
}) | ||
|
||
test_that("arranged computed columns are not inlined away", { | ||
lf <- lazy_frame(x = 1) | ||
|
||
# shouldn't inline | ||
out <- lf %>% mutate(z = 2) %>% arrange(x, z) %>% select(x) | ||
# should inline | ||
out2 <- lf %>% mutate(z = 2) %>% arrange(x, z) %>% select(x, z) | ||
|
||
inner_query <- out$lazy_query$x | ||
expect_snapshot({ | ||
lf %>% mutate(z = 1) %>% arrange(x, z) %>% select(x) | ||
}) | ||
expect_s3_class(inner_query, "lazy_select_query") | ||
expect_equal( | ||
inner_query$order_by, | ||
list(quo(x), quo(z)), | ||
ignore_formula_env = TRUE | ||
) | ||
expect_equal(op_vars(inner_query), c("x", "z")) | ||
expect_equal(op_vars(out$lazy_query), "x") | ||
expect_equal( | ||
# order vars in a subquery are dropped | ||
inner_query[setdiff(names(inner_query), "order_vars")], | ||
out2$lazy_query[setdiff(names(out2$lazy_query), "order_vars")] | ||
) | ||
}) | ||
|
||
# sql_render -------------------------------------------------------------- | ||
|
||
test_that("multiple selects are collapsed", { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few tweaks here to hopefully make the logic a bit clearer.