-
Notifications
You must be signed in to change notification settings - Fork 168
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
Unable to use quantile() in mutate() in DuckDB #1487
Comments
This is the SQL that we're generating for duckdb here: SELECT
mtcars.*,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY mpg) OVER () AS mpg_25th
FROM mtcars |
Thank you. I still get the following error running the SQL you recommended. Error: {"exception_type":"Parser","exception_message":"ORDER BY is not implemented for window functions!"} Here is the code I use. library(tidyverse)
library(DBI)
library(dbplyr)
con <- DBI::dbConnect(duckdb::duckdb())
copy_to(con, mtcars)
dbGetQuery(
con,
'SELECT
mtcars.*,
PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY mpg) OVER () AS mpg_25th
FROM mtcars;'
)
# Error: {"exception_type":"Parser","exception_message":"ORDER BY is not implemented for window functions!"} Could this be related to an issue from Duckdb? |
I was just including the SQL that dbplyr generates to complete your reprex. |
I recently found that the library(tidyverse)
library(DBI)
library(dbplyr)
con <- DBI::dbConnect(duckdb::duckdb())
copy_to(con, mtcars)
tbl(con, "mtcars") |>
summarize(mpg_25th = quantile(mpg, 0.25, na.rm = TRUE)) The corresponding SQL code is SELECT PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY mpg) AS mpg_25th
FROM mtcars As a temporary workaround, I could use the original dataframe to perform a left join with the summarised dataframe to get the same results. |
I'm trying to calculate the 25th quantile value in DuckDB, using the
mutate()
function fromdbplyr
. I got an error message saying "ORDER BY is not implemented for window functions!". However, DuckDB's documentation indicates support for thequantile
function viaquantile_count()
, saying "All aggregate functions can be used in a windowing context" (DuckDB Documentation on Window Functions).Here's the reprex:
Here's the reprex:
Would you please to fix this issue? Thank you.
The text was updated successfully, but these errors were encountered: