Skip to content

fix: preserve approximate percentile arguments with inline ORDER BY - #24411

Open
haohuaijin wants to merge 3 commits into
apache:mainfrom
haohuaijin:codex/fix-inline-order-by-aggregate-args
Open

fix: preserve approximate percentile arguments with inline ORDER BY#24411
haohuaijin wants to merge 3 commits into
apache:mainfrom
haohuaijin:codex/fix-inline-order-by-aggregate-args

Conversation

@haohuaijin

@haohuaijin haohuaijin commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Inline ORDER BY handling incorrectly removes percentile or weight arguments from approximate percentile aggregates.

What changes are included in this PR?

Only remove the first aggregate argument when it matches the inline ordering expression. Add regression coverage for approx_percentile_cont and approx_percentile_cont_with_weight.

Are these changes tested?

Yes. The aggregate.slt regression tests, ./dev/rust_lint.sh, and cargo clippy --all-targets --all-features -- -D warnings all pass.

Are there any user-facing changes?

Valid approximate percentile queries using inline ORDER BY now plan and execute successfully.

@github-actions github-actions Bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Aug 16, 2026
@codecov-commenter

codecov-commenter commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.23%. Comparing base (bb038a6) to head (014f14d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24411      +/-   ##
==========================================
- Coverage   81.23%   81.23%   -0.01%     
==========================================
  Files        1112     1112              
  Lines      390635   390630       -5     
  Branches   390635   390630       -5     
==========================================
- Hits       317350   317332      -18     
- Misses      54650    54657       +7     
- Partials    18635    18641       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Jefffrey Jefffrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this makes sense in keeping existing ordered set aggregates in line with percentile_cont (which doesnt suffer this issue since i think the code was specifically designed for how many arguments it has?)

though @jayzhan211 does have thoughts on how we should handle ORDER BYs with these functions

Comment thread datafusion/sql/src/expr/function.rs Outdated
Comment thread datafusion/sql/src/expr/function.rs
@haohuaijin

Copy link
Copy Markdown
Contributor Author

Thanks @Jefffrey for reviews, i apply suggestion in 32f7528

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline ORDER BY drops arguments for approximate percentile aggregates

3 participants