Open
Description
Not sure if this is a bug or not, but I have run into the following issue.
My actual workflow is with company data but I have managed to reproduce it with a pipeline that is close enough:
This works:
lf <- dbplyr::lazy_frame(
a = TRUE, b = 1, c = 2, d = "z",
con = dbplyr::simulate_hana()
)
lf |>
dplyr::filter(.data$a == TRUE) |>
dplyr::group_by(.data$b) |>
dplyr::mutate(e = .data$b + .data$c) |>
dbplyr::window_order(desc(.data$e)) |> ## Note this line.
dplyr::distinct(.data$d, .keep_all = TRUE)
Returns:
<SQL>
SELECT `a`, `b`, `c`, `d`, `e`
FROM (
SELECT
`q01`.*,
ROW_NUMBER() OVER (PARTITION BY `b`, `d` ORDER BY `e` DESC) AS `col01`
FROM (
SELECT `df`.*, `b` + `c` AS `e`
FROM `df`
WHERE (`a` = TRUE)
) AS `q01`
) AS `q01`
WHERE (`col01` = 1)
This does not work:
lf <- dbplyr::lazy_frame(
a = TRUE, b = 1, c = 2, d = "z",
con = dbplyr::simulate_hana()
)
lf |>
dplyr::filter(.data$a == TRUE) |>
dplyr::group_by(.data$b) |>
dplyr::mutate(e = .data$b + .data$c) |>
dbplyr::window_order(dplyr::desc(.data$e)) |> ## Note: I have now fully-qualified the desc() call.
dplyr::distinct(.data$d, .keep_all = TRUE)
Returns:
Error in `get_env()` at dbplyr/R/translate-sql.R:166:3:
! Can't extract an environment from a call.
Run `rlang::last_trace()` to see where the error occurred.
Metadata
Metadata
Assignees
Labels
No labels