Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 26, 2025

The dbplyr quantile() translation generates PERCENTILE_CONT(probs) WITHIN GROUP (ORDER BY x) OVER () which DuckDB doesn't support as a window function.

library(dbplyr)
library(dplyr)

con <- DBI::dbConnect(duckdb::duckdb())
mtcars_db <- copy_to(con, mtcars)

# Previously failed with: "Aggregate Function with name percentile_cont does not exist!"
mutate(mtcars_db, mpg_25th = quantile(mpg, 0.25, na.rm = TRUE))

Changes

  • Added custom quantile aggregate translation using QUANTILE_CONT(x, probs) syntax
  • Added custom quantile window translation with proper win_over() wrapping
  • Added QUANTILE_CONT to globalVariables for R CMD check
  • Added translation tests for aggregate and window contexts

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cloud.r-project.org
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R /opt/R/4.5.2/lib/R/bin/exec/R -q -e options(repos~&#43;~=~&#43;~c(CRAN=&#39;REDACTED&#39;));~&#43;~install.packages(c(&#39;DBI&#39;,~&#43;~&#39;dbplyr&#39;,~&#43;~&#39;dplyr&#39;,~&#43;~&#39;testthat&#39;,~&#43;~&#39;rlang&#39;,~&#43;~&#39;cli&#39;,~&#43;~&#39;withr&#39;,~&#43;~&#39;brio&#39;)) (dns block)
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)
    • Triggering command: /usr/bin/curl curl -I REDACTED (dns block)
  • cran.r-project.org
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R /opt/R/4.5.2/lib/R/bin/exec/R -q -e install.packages(c(&#39;DBI&#39;,~&#43;~&#39;dbplyr&#39;,~&#43;~&#39;dplyr&#39;,~&#43;~&#39;testthat&#39;),~&#43;~repos=&#39;REDACTED&#39;) (dns block)
  • cran.rstudio.com
    • Triggering command: /opt/R/4.5.2/lib/R/bin/exec/R /opt/R/4.5.2/lib/R/bin/exec/R -q -e install.packages(c(&#39;DBI&#39;,~&#43;~&#39;dbplyr&#39;,~&#43;~&#39;dplyr&#39;,~&#43;~&#39;testthat&#39;,~&#43;~&#39;rlang&#39;,~&#43;~&#39;cli&#39;,~&#43;~&#39;withr&#39;,~&#43;~&#39;brio&#39;),~&#43;~repos=&#39;REDACTED&#39;) (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Incorrect quantile translation</issue_title>
<issue_description>``` r
library(dbplyr)
library(dplyr, warn.conflicts = FALSE)

con <- DBI::dbConnect(duckdb::duckdb())
mtcars_db <- copy_to(con, mtcars)

mutate(mtcars_db, mpg_25th = quantile(mpg, 0.25, na.rm = TRUE))
#> Error in collect():
#> ! Failed to collect lazy table.
#> Caused by error in dbSendQuery():
#> ! Catalog Error: Aggregate Function with name percentile_cont does not exist!
#> Did you mean "pi"?
#>
#> LINE 3: PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY mpg) OVER ...
#> ^
#> ℹ Context: rapi_prepare
#> ℹ Error type: CATALOG
#> ℹ Raw message: Aggregate Function with name percentile_cont does not exist!
#> Did you mean "pi"?
#>
#> LINE 3: PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY mpg) OVER ...
#> ^


<sup>Created on 2025-11-26 with [reprex v2.1.1](https://reprex.tidyverse.org)</sup>

A little unfortunate we get two errors too.</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix incorrect quantile translation in lazy table Fix quantile translation to use DuckDB native QUANTILE_CONT syntax Nov 26, 2025
Copilot AI requested a review from krlmlr November 26, 2025 13:24
@krlmlr krlmlr changed the title Fix quantile translation to use DuckDB native QUANTILE_CONT syntax fix: Fix translation of quantile() to use DuckDB's native QUANTILE_CONT() syntax Nov 26, 2025
@krlmlr krlmlr marked this pull request as ready for review November 26, 2025 14:27
@krlmlr krlmlr enabled auto-merge (squash) November 26, 2025 14:27
@krlmlr krlmlr merged commit 76aa825 into main Nov 26, 2025
6 checks passed
@krlmlr krlmlr deleted the copilot/fix-quantile-translation-error branch November 26, 2025 14:56
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

Successfully merging this pull request may close these issues.

Incorrect quantile translation

2 participants