refactor: address review feedback on percentile_cont(DISTINCT) accumulator - #23946
Merged
Conversation
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
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
approved these changes
Jul 28, 2026
neilconway
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the quick turnaround! lgtm
Member
Author
|
Thank you @neilconway for the reviews |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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
This was referenced Jul 28, 2026
AdamGS
pushed a commit
to AdamGS/arrow-datafusion
that referenced
this pull request
Jul 29, 2026
…edian` (apache#23954) ## Which issue does this PR close? - Closes apache#23953 ## Rationale for this change This PR makes three improvements to non-distinct `PercentileContAccumulator` and `MedianAccumulator`, inspired by recent work on `percentile_cont(DISTINCT)` (apache#23946): 1. Switch from SipHash to foldhash for internal hash maps 2. Add a null-free fast path to `update_batch` and `retract_batch` 3. Raise an error if we attempt to retract an unknown value in `retract_batch`, rather than silently ignoring it. Benchmarks: percentile_cont no_nulls window=256 -61.1% (249.0 -> 96.6 us) percentile_cont with_nulls window=256 -59.4% (232.7 -> 94.5 us) percentile_cont no_nulls window=4096 -50.9% (756.3 -> 370.4 us) percentile_cont with_nulls window=4096 -48.2% (552.2 -> 286.2 us) percentile_cont no_nulls window=16384 -47.3% (2.311 -> 1.218 ms) percentile_cont with_nulls window=16384 -42.0% (1.465 -> 0.851 ms) median no_nulls window=256 -62.8% (247.0 -> 92.0 us) median with_nulls window=256 -59.8% (228.8 -> 92.0 us) median no_nulls window=4096 -40.0% (411.4 -> 246.6 us) median with_nulls window=4096 -39.4% (364.4 -> 221.0 us) median no_nulls window=16384 -31.5% (1.107 -> 0.759 ms) median with_nulls window=16384 -32.9% (0.947 -> 0.637 ms) ## What changes are included in this PR? See above. ## Are these changes tested? Yes: existing tests pass, new tests added for the null-free fast path and the improved error handling. ## Are there any user-facing changes? No.
kosiew
pushed a commit
to kosiew/datafusion
that referenced
this pull request
Aug 12, 2026
…lator (apache#23946) ## Rationale for this change Follow-up to post-merge review feedback from @neilconway on apache#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.
kosiew
pushed a commit
to kosiew/datafusion
that referenced
this pull request
Aug 12, 2026
…edian` (apache#23954) ## Which issue does this PR close? - Closes apache#23953 ## Rationale for this change This PR makes three improvements to non-distinct `PercentileContAccumulator` and `MedianAccumulator`, inspired by recent work on `percentile_cont(DISTINCT)` (apache#23946): 1. Switch from SipHash to foldhash for internal hash maps 2. Add a null-free fast path to `update_batch` and `retract_batch` 3. Raise an error if we attempt to retract an unknown value in `retract_batch`, rather than silently ignoring it. Benchmarks: percentile_cont no_nulls window=256 -61.1% (249.0 -> 96.6 us) percentile_cont with_nulls window=256 -59.4% (232.7 -> 94.5 us) percentile_cont no_nulls window=4096 -50.9% (756.3 -> 370.4 us) percentile_cont with_nulls window=4096 -48.2% (552.2 -> 286.2 us) percentile_cont no_nulls window=16384 -47.3% (2.311 -> 1.218 ms) percentile_cont with_nulls window=16384 -42.0% (1.465 -> 0.851 ms) median no_nulls window=256 -62.8% (247.0 -> 92.0 us) median with_nulls window=256 -59.8% (228.8 -> 92.0 us) median no_nulls window=4096 -40.0% (411.4 -> 246.6 us) median with_nulls window=4096 -39.4% (364.4 -> 221.0 us) median no_nulls window=16384 -31.5% (1.107 -> 0.759 ms) median with_nulls window=16384 -32.9% (0.947 -> 0.637 ms) ## What changes are included in this PR? See above. ## Are these changes tested? Yes: existing tests pass, new tests added for the null-free fast path and the improved error handling. ## Are there any user-facing changes? No.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Follow-up to post-merge review feedback from @neilconway on #23913.
What changes are included in this PR?
RandomStatefor the distinct-value count map instead of the standard library's default SipHash (the sharedGenericDistinctBufferalready does this; the merged fix regressed to SipHash on this hot path).estimate_memory_sizeinsize()instead of a hand-rolled capacity calculation.update_batch/retract_batch(skip per-element validity checks when the input has no nulls), mirroringGenericDistinctBuffer.ORDER BYto the sliding-window regression test so its row order is deterministic.Are these changes tested?
Yes — existing percentile unit tests and the full
aggregate.sltpass.Are there any user-facing changes?
No.