Skip to content

refactor: address review feedback on percentile_cont(DISTINCT) accumulator - #23946

Merged
viirya merged 4 commits into
apache:mainfrom
viirya:followup-distinct-percentile
Jul 28, 2026
Merged

refactor: address review feedback on percentile_cont(DISTINCT) accumulator#23946
viirya merged 4 commits into
apache:mainfrom
viirya:followup-distinct-percentile

Conversation

@viirya

@viirya viirya commented Jul 28, 2026

Copy link
Copy Markdown
Member

Rationale for this change

Follow-up to post-merge review feedback from @neilconway on #23913.

What changes are included in this PR?

  • Use the fast foldhash RandomState for the distinct-value count map instead of the standard library's default SipHash (the shared GenericDistinctBuffer already does this; the merged fix regressed to SipHash on this hot path).
  • Use estimate_memory_size in size() instead of a hand-rolled capacity calculation.
  • Adopt the null-free fast path in update_batch/retract_batch (skip per-element validity checks when the input has no nulls), mirroring GenericDistinctBuffer.
  • Add ORDER BY to the sliding-window regression test so its row order is deterministic.

Are these changes tested?

Yes — existing percentile unit tests and the full aggregate.slt pass.

Are there any user-facing changes?

No.

Follow-up to the DistinctPercentileContAccumulator fix, addressing
post-merge review comments:

- Use the fast foldhash RandomState for the `counts` map instead of the
  standard library's default SipHash, matching GenericDistinctBuffer.
- Compute size() via estimate_memory_size, mirroring the other distinct
  accumulators.
- Add a null-free fast path to update_batch and retract_batch that skips
  the per-element validity check when the input array has no nulls.
- Add ORDER BY id to the sliding-window regression query in aggregate.slt
  so its output row order is deterministic.

Co-authored-by: Claude Code
@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jul 28, 2026
viirya added 2 commits July 28, 2026 08:55
Add a grouped percentile_cont(DISTINCT ...) regression test. A GROUP BY
with target_partitions=4 forces two-phase (Partial + FinalPartitioned)
aggregation, so the distinct accumulator's state() and merge_batch()
paths run — the paths the previous whole-table regression queries did
not reach (flagged by patch-coverage review on apache#23913). Duplicate values
within each group also verify multiplicity is preserved across the
per-partition merge.

Co-authored-by: Claude Code
Per review discussion: if `retract_batch` is asked to remove a value not
in the count map, the accumulator's state has diverged from the window
frame and continuing would silently produce wrong results. Return an
`internal_err!` instead of skipping, so the inconsistency surfaces rather
than yielding a wrong answer.

Co-authored-by: Claude Code

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

Thanks for the quick turnaround! lgtm

@viirya

viirya commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Thank you @neilconway for the reviews

@codecov-commenter

codecov-commenter commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.07692% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.70%. Comparing base (994fc81) to head (11cec2d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...afusion/functions-aggregate/src/percentile_cont.rs 73.07% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #23946   +/-   ##
=======================================
  Coverage   80.69%   80.70%           
=======================================
  Files        1095     1095           
  Lines      372626   372542   -84     
  Branches   372626   372542   -84     
=======================================
- Hits       300700   300651   -49     
+ Misses      53978    53924   -54     
- Partials    17948    17967   +19     

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

Add a sliding-window percentile_cont(DISTINCT ...) regression over data
containing a NULL positioned so that both the update_batch (NULL row
enters the frame) and retract_batch (NULL row leaves the frame) code
paths take the null_count() > 0 branch. Verified via temporary eprintln
that both branches execute; the previous distinct-percentile tests used
no NULLs and left those branches uncovered.

Co-authored-by: Claude Code
@viirya
viirya added this pull request to the merge queue Jul 28, 2026
Merged via the queue into apache:main with commit 73b8ad3 Jul 28, 2026
37 checks passed
@viirya
viirya deleted the followup-distinct-percentile branch July 28, 2026 22:37
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.

3 participants