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

Bug in transmute translation #313

Closed
mgirlich opened this issue Jun 4, 2019 · 3 comments
Closed

Bug in transmute translation #313

mgirlich opened this issue Jun 4, 2019 · 3 comments
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL
Milestone

Comments

@mgirlich
Copy link
Collaborator

mgirlich commented Jun 4, 2019

There is an error in the SQL generation for transmute

library(dplyr)
library(dbplyr)

df <- data.frame(x = 1, y = 2)

# doesn't work
tbl_lazy(df, con = simulate_postgres()) %>% 
  transmute(x, x2 = x + y, y)
#> <SQL>
#> SELECT `x`, `x` + `y` AS `x2`, `y`
#> FROM (SELECT `x`
#> FROM `df`) `dbplyr_001`

# works
tbl_lazy(df, con = simulate_postgres()) %>% 
  transmute(x, y, x2 = x + y)
#> <SQL>
#> SELECT `x`, `y`, `x` + `y` AS `x2`
#> FROM (SELECT `x`, `y`
#> FROM `df`) `dbplyr_002`

Created on 2019-06-04 by the reprex package (v0.3.0)

Created on 2019-06-04 by the reprex package (v0.3.0)

@hadley
Copy link
Member

hadley commented Jun 4, 2019

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

lf <- lazy_frame(x = 1, y = 2)
transmute(lf, x, x2 = x + y, y)
#> <SQL>
#> SELECT `x`, `x` + `y` AS `x2`, `y`
#> FROM (SELECT `x`
#> FROM `df`) `dbplyr_001`

Created on 2019-06-04 by the reprex package (v0.2.1.9000)

@hadley hadley added bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL labels Jun 4, 2019
@hadley
Copy link
Member

hadley commented Jun 4, 2019

Probably overly aggressive query optimisation

@hadley
Copy link
Member

hadley commented Sep 24, 2020

Interestingly, the equivalent mutate() works too:

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

lf <- lazy_frame(x = 1, y = 2)
transmute(lf, x, x2 = x + y, y)
#> <SQL>
#> SELECT `x`, `x` + `y` AS `x2`, `y`
#> FROM (SELECT `x`
#> FROM `df`) `q01`
mutate(lf, x, x2 = x + y, y)
#> <SQL>
#> SELECT `x`, `y`, `x` + `y` AS `x2`
#> FROM (SELECT `x`, `y`
#> FROM `df`) `q01`

Created on 2020-09-24 by the reprex package (v0.3.0.9001)

@hadley hadley added this to the 2.0.0 milestone Sep 24, 2020
@hadley hadley closed this as completed in 777e789 Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL
Projects
None yet
Development

No branches or pull requests

2 participants