-
Notifications
You must be signed in to change notification settings - Fork 170
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
R expression to SQL expression translation bug #634
Comments
we can see that expressions
|
the difference is how they are generated. |
it seems that the SQL translation is correct while the R version inserts a parenthesis for some reason |
|
require(rlang)
#> Loading required package: rlang
require(dplyr)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
require(dbplyr)
#> Loading required package: dbplyr
#>
#> Attaching package: 'dbplyr'
#> The following objects are masked from 'package:dplyr':
#>
#> ident, sql
e<-expr(!!expr((1 / ( 1 + abs(x)))-1)*sign(x))
mutate(memdb_frame(x=-3),!!e)
#> # Source: lazy query [?? x 2]
#> # Database: sqlite 3.35.2 [:memory:]
#> x `((1/(1 + abs(x))) - 1) * sign(x)`
#> <dbl> <dbl>
#> 1 -3 1.25
mutate(memdb_frame(x=-3),!!parse_expr(deparse(e)))
#> # Source: lazy query [?? x 2]
#> # Database: sqlite 3.35.2 [:memory:]
#> x `((1/(1 + abs(x))) - 1) * sign(x)`
#> <dbl> <dbl>
#> 1 -3 0.75 Created on 2021-04-11 by the reprex package (v2.0.0) |
I simplified the reprex library(dplyr, warn.conflicts = FALSE)
library(dbplyr)
translate_sql(!!expr(2 - 1) * x)
#> <SQL> 2.0 - 1.0 * `x`
translate_sql(!!expr((2 - 1) * x))
#> <SQL> (2.0 - 1.0) * `x` Created on 2021-04-12 by the reprex package (v2.0.0) In build_sql(x, sql(f), y) where |
the expression
((1/(1 + abs(x))) - 1) * sign(x)
does not seem to translate accurately into SQL undercertain conditions
in the below example, the expressions
bug1
andbug2
are the same, the equality test returns TRUE.expression
bug1
produces different results inR
andSQL
expression
bug2
produces the same results inR
andSQL
The text was updated successfully, but these errors were encountered: