Skip to content

feat: widen percentile input to use larger precision - #24577

Merged
kosiew merged 4 commits into
apache:mainfrom
theirix:percentile-cont-decimal-regr
Aug 29, 2026
Merged

feat: widen percentile input to use larger precision#24577
kosiew merged 4 commits into
apache:mainfrom
theirix:percentile-cont-decimal-regr

Conversation

@theirix

@theirix theirix commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

A follow-up for #24419, which introduced pure-decimal interpolation, where a smaller interpolation precision was used for Decimal32 types with Euclidean interpolation. Seems like, a smaller precision for Decimal32 is not enough, and the value was saturated to zero.

Solution - just widen i32 inputs to i64 to handle edge cases. In this case, we can use the same logical interpolation precision 10^6 everywhere.

What changes are included in this PR?

  • Interpolation precision is now the only one
  • scale_by_num now widens i32 inputs to i64

Are these changes tested?

  • The mentioned case
  • More test cases to overflow the interpolator, matched with DuckDB and DataFusion floating interpolator

Are there any user-facing changes?

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Aug 22, 2026
@codecov-commenter

codecov-commenter commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.41176% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.48%. Comparing base (32badcb) to head (bd7f54c).
⚠️ Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
...afusion/functions-aggregate/src/percentile_cont.rs 79.41% 0 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24577      +/-   ##
==========================================
+ Coverage   81.37%   81.48%   +0.10%     
==========================================
  Files        1116     1122       +6     
  Lines      397509   404264    +6755     
  Branches   397509   404264    +6755     
==========================================
+ Hits       323461   329398    +5937     
- Misses      55110    55551     +441     
- Partials    18938    19315     +377     

☔ 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.

@theirix
theirix marked this pull request as ready for review August 22, 2026 12:23
@theirix

theirix commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@Jefffrey could you have a look please? A follow-up for exact percentiles

@kosiew kosiew 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.

@theirix, thanks for working on this. The change looks good to me. Using the shared interpolation precision and widening the bounded remainder arithmetic to i64 addresses the Decimal32 issue cleanly. I just have one non-blocking suggestion around coverage for the overflow fallback path.


// Happy path: `upper - lower` does not overflow
// (could be a case for Decimal128 with max precision)
if let Ok(delta) = upper.sub_checked(lower) {

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.

Could we add a focused unit test that exercises the upper.sub_checked(lower) overflow fallback? For example, Decimal32 with i32::MIN and i32::MAX at a non-endpoint fraction should force this path. The new SQL tests cover the normal delta path nicely, but a test like this would also lock down the separately weighted extrema path that relies on the widened remainder arithmetic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, it's a good idea - added a specialised test.

@kosiew

kosiew commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🚀
@theirix
Thank you for your contribution.

@kosiew
kosiew added this pull request to the merge queue Aug 29, 2026
Merged via the queue into apache:main with commit 5bd4721 Aug 29, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

percentile_cont is wrong for Decimal32 with lower interpolation precision

3 participants