Skip to content
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

slice_* function issue with data masking #1294

Closed
bairdj opened this issue Jun 5, 2023 · 0 comments · Fixed by #1302
Closed

slice_* function issue with data masking #1294

bairdj opened this issue Jun 5, 2023 · 0 comments · Fixed by #1302

Comments

@bairdj
Copy link
Contributor

bairdj commented Jun 5, 2023

There is an issue when slice_* calls are translated to SQL when the order_by parameter uses .data$ notation rather than a bare symbol name. The generated SQL erroneously prefixes .data to the order by clause, which causes the query to fail.

# Expected behaviour (using local df)
mtcars %>%
  group_by(.data$cyl) %>%
  slice_max(.data$mpg)

# Returns 1 row per group, ordered by MPG

# Observed behaviour (fails)
rem_mtcars <- copy_to(connection, mtcars)
rem_mtcars %>%
  group_by(.data$cyl) %>%
  slice_max(.data$mpg)

# This works
rem_mtcars %>%
  group_by(.data$cyl) %>%
  slice_max(mpg)

An example of the generated SQL is

ROW_NUMBER() OVER (PARTITION BY "cyl" ORDER BY ".data"."mpg" DESC)

The translation works fine when using arrange, it is only for the window functions I have observed the issue.

I've tested this with Redshift and SQLite with the same output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant