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
dbplyr::sql_variant doesn't seem to work as it should #3117
Comments
Could you please rework your reproducible example to use the reprex package ? That makes it easier to see both the input and the output, formatted in such a way that I can easily re-run in a local session. |
There you go library(dbplyr)
## Copy pasting the example from doc, my comments after double "#"
# An example of adding some mappings for the statistical functions that
# postgresql provides: http://bit.ly/K5EdTn
postgres_agg <- sql_translator(.parent = base_agg,
cor = sql_prefix("corr"),
cov = sql_prefix("covar_samp"),
sd = sql_prefix("stddev_samp"),
var = sql_prefix("var_samp")
)
postgres_var <- sql_variant(
base_scalar,
postgres_agg
)
#> Warning: Translator is missing window functions:
#> cor, cov, max, mean, min, n, n_distinct, sd, sum, var
translate_sql(cor(x, y), variant = postgres_var)
#> <SQL> COR("x", "y")
#> <SQL> "postgres_var"
translate_sql(sd(income / years), variant = postgres_var)
#> <SQL> SD("income" / "years")
#> <SQL> "postgres_var"
## we just defined translations for cor and sd, I expected to see:
## > <SQL> CORR("x", "y")
## > <SQL> STDDEV_SAMP("income" / "years")
## If I try a function translated by default such as `mean` however I get a translation:
translate_sql(mean(x))
#> <SQL> avg("x") OVER () |
|
I see, thank you. The only example for What route would you recommend to define one's own |
Thanks! |
I am cross posting this from stack overflow as it seems to be a bug rather than a misunderstanding :
Let's take a look at the example in
?sql_variant
:We define a new translator function for aggregated functions, expanded from the default one:
We then define a new variant, which is made from translation functions of the 3 different types (here 2):
These don't look translated to me, shouldn't they be
"CORR"
and"STDDEV_SAMP"
?This one behaves as expected, which is just like the other 2.
On the other hand default translated functions work, see:
It's a bug right ? or am I missing something ?
My goal is to create some variants for
Oracle
and use it in the following fashion,then for more complicated functions (example withSQLite
to be reproducible):The text was updated successfully, but these errors were encountered: