Skip to content

[QECO-1569] Preserve projected constants in aggregate arguments - #24005

Draft
Adam-Alani wants to merge 1 commit into
apache:mainfrom
Adam-Alani:adam.alani/propagate-percentile-constants
Draft

[QECO-1569] Preserve projected constants in aggregate arguments#24005
Adam-Alani wants to merge 1 commit into
apache:mainfrom
Adam-Alani:adam.alani/propagate-percentile-constants

Conversation

@Adam-Alani

Copy link
Copy Markdown

Why

Aggregate arguments that are constant can lose that property when a subquery or CTE projects them as columns. approx_percentile_cont then rejects a projected literal because its accumulator cannot evaluate the physical column without input, even though the defining expression is query-global and constant.

What

This preserves column-free, non-volatile aggregate arguments through projection and subquery-alias boundaries so normal expression simplification can evaluate them before physical planning. Row-varying columns remain unchanged and continue to be rejected by percentile validation.

How

The simplify-expressions rule collects safe constant definitions from projection chains, remaps them through subquery aliases, and substitutes only matching aggregate-expression columns while preserving output names. Scalar subqueries, volatile expressions, and expressions with column dependencies are excluded.

Validated with:

  • cargo test --test sqllogictests -p datafusion-sqllogictest -- aggregate.slt
  • cargo test -p datafusion-optimizer simplify_expressions::simplify_exprs
  • cargo clippy -p datafusion-optimizer --all-features -- -D warnings
  • cargo fmt --all -- --check

Companion to #23997; the PRs are independent and can merge in either order.

Preserve column-free constants through projection and alias boundaries so aggregate arguments can be simplified without accepting row-varying columns.
@github-actions github-actions Bot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant