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

Faulty SQL generation when combining rename() with join_by(between()) #1572

Open
lschneiderbauer opened this issue Jan 22, 2025 · 0 comments

Comments

@lschneiderbauer
Copy link

lschneiderbauer commented Jan 22, 2025

The SQL generation seems to have problems when combining renaming with the join_by(between()) clause.

The following SQL fails when executing on a backend (binding error): it complains that it cannot find column 'z'.
dbplyr seems to translate the first inequality correctly, while it does not apply the correct substitution for the second inequality.

library(dplyr)
#> 
#> Attache Paket: 'dplyr'
#> Die folgenden Objekte sind maskiert von 'package:stats':
#> 
#>     filter, lag
#> Die folgenden Objekte sind maskiert von 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(dbplyr)
#> 
#> Attache Paket: 'dbplyr'
#> Die folgenden Objekte sind maskiert von 'package:dplyr':
#> 
#>     ident, sql

ldf1 <- tbl_lazy(tibble(x = 1))
ldf2 <- tbl_lazy(tibble(y = 1))

ldf1 |> 
  left_join(
    ldf2 |> rename(z = y),
    join_by(between(x, z, z))
  )
#> <SQL>
#> SELECT `x`, `y` AS `z`
#> FROM `df` AS `df_LHS`
#> LEFT JOIN `df` AS `df_RHS`
#>   ON (`df_LHS`.`x` >= `df_RHS`.`y` AND `df_LHS`.`x` <= `df_RHS`.`z`)

Created on 2025-01-22 with reprex v2.1.1

I expect

#> <SQL>
#> SELECT `x`, `y` AS `z`
#> FROM `df` AS `df_LHS`
#> LEFT JOIN `df` AS `df_RHS`
#>   ON (`df_LHS`.`x` >= `df_RHS`.`y` AND `df_LHS`.`x` <= `df_RHS`.`y`)
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

No branches or pull requests

1 participant