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

select() fails after specific sequence of dplyr commands #1437

Closed
edgararuiz opened this issue Jan 9, 2024 · 1 comment · Fixed by #1446
Closed

select() fails after specific sequence of dplyr commands #1437

edgararuiz opened this issue Jan 9, 2024 · 1 comment · Fixed by #1446

Comments

@edgararuiz
Copy link
Collaborator

It seems that when you sequence a group_by(), then a mutate(), and lastly an arrange(), dbplyr is not able to find the variable created by the mutate() when using select(). This works against a regular data frame. Reprex here:

suppressPackageStartupMessages(library(dplyr)) 
suppressPackageStartupMessages(library(dbplyr))
memdb_frame(
  Name = c("Alice", "Bob", "Alice", "Bob", "Charlie"),
  Subject = c("Math", "Math", "English", "English", "Math"),
  Score = c(90, 85, 88, 92, 78)
) %>% 
  group_by(Name) %>% 
  mutate(AvgScore = 1) %>% 
  ungroup() %>% 
  arrange(AvgScore, Name) %>% 
  select(Name)
#> Error in `collect()`:
#> ! Failed to collect lazy table.
#> Caused by error:
#> ! no such column: AvgScore

Created on 2024-01-09 with reprex v2.0.2

Initially reported as a possible bug in sparklyr here: sparklyr/sparklyr#3413

@hadley
Copy link
Member

hadley commented Jan 9, 2024

Slightly more minimal reprex:

library(dbplyr)
library(dplyr, warn.conflicts = FALSE)

db <- lazy_frame(x = 1, y = 2) 

db %>% 
  mutate(z = 1) %>% 
  arrange(x, z) %>%
  select(x)
#> <SQL>
#> SELECT `x`
#> FROM `df`
#> ORDER BY `x`, `z`

Created on 2024-01-09 with reprex v2.0.2.9000

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.

2 participants