Skip to content

Commit

Permalink
more descriptive inlining tests for arranged computed columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ejneer committed Mar 2, 2024
1 parent df29760 commit e3dc35e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
16 changes: 0 additions & 16 deletions tests/testthat/_snaps/verb-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,6 @@
Error in `select()`:
! This tidyselect interface doesn't support predicates.

# computed columns are not inlined away

Code
lf %>% mutate(z = 1) %>% arrange(x, z) %>% select(x)
Condition
Warning:
ORDER BY is ignored in subqueries without LIMIT
i Do you need to move arrange() later in the pipeline or use window_order() instead?
Output
<SQL>
SELECT `x`
FROM (
SELECT `df`.*, 1.0 AS `z`
FROM `df`
) AS `q01`

# multiple selects are collapsed

Code
Expand Down
26 changes: 21 additions & 5 deletions tests/testthat/test-verb-select.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,28 @@ test_that("where() isn't suppored", {
})
})

test_that("computed columns are not inlined away", {
lf <- lazy_frame(x = 1, y = 2)
test_that("arranged computed columns are not inlined away", {
lf <- lazy_frame(x = 1)

expect_snapshot({
lf %>% mutate(z = 1) %>% arrange(x, z) %>% select(x)
})
# 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_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 --------------------------------------------------------------
Expand Down

0 comments on commit e3dc35e

Please sign in to comment.