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

distinct ignores rhs when there is a lhs (renaming result columns) #154

Closed
sverchkov opened this issue Sep 6, 2018 · 6 comments
Closed
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL
Milestone

Comments

@sverchkov
Copy link
Contributor

library( dplyr, warn.conflicts = F )

df_tib <- tibble( a=c(1,1,2,2), b=c(1,2,1,2) )
df_sql <- dbplyr::memdb_frame( a=c(1,1,2,2), b=c(1,2,1,2) )

df_tib %>% distinct( x = a )
#> # A tibble: 2 x 1
#>       x
#>   <dbl>
#> 1     1
#> 2     2

res <- df_sql %>% distinct( x = a )
res %>% show_query()
#> <SQL>
#> SELECT `x`
#> FROM `bigofxlnjv`
#> GROUP BY `x`
res
#> Error in result_create(conn@ptr, statement): no such column: x

Created on 2018-09-06 by the reprex
package
(v0.2.0).

I think the correct translation is SELECT DISTINCT "a" AS "x".

@edgararuiz-zz

This comment has been minimized.

@sverchkov

This comment has been minimized.

@hadley hadley added bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL labels Jan 2, 2019
@hadley hadley added this to the v1.4.0 milestone Jan 9, 2019
@hadley
Copy link
Member

hadley commented Jan 10, 2019

Needs dplyr:::distinct_vars() to be exported first

@hadley
Copy link
Member

hadley commented Mar 13, 2019

Now called distinct_prepare(). Will need bump to dplyr 0.8.0.

@hadley
Copy link
Member

hadley commented Mar 14, 2019

Nope, not worth it — distinct_prepare() assumes too much about the data frame, and it'll be easiest to reimplement in dbplyr.

@hadley hadley closed this as completed in 3bfecdf Mar 14, 2019
@hadley
Copy link
Member

hadley commented Mar 14, 2019

The fix is suspiciously simple, but seems to work 😄

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

3 participants