fix: correct percentile_cont(DISTINCT) accumulation and sliding-window retract - #23913
Open
viirya wants to merge 1 commit into
Open
fix: correct percentile_cont(DISTINCT) accumulation and sliding-window retract#23913viirya wants to merge 1 commit into
viirya wants to merge 1 commit into
Conversation
…w retract `DistinctPercentileContAccumulator` had two bugs: 1. Panic on every distinct query. `update_batch` forwarded all argument columns to `GenericDistinctBuffer::update_batch`, which asserts a single input array. `percentile_cont` always passes two columns (the value and the percentile literal), so any `percentile_cont(DISTINCT x, p)` panicked with "DistinctValuesBuffer::update_batch expects only a single input array". 2. Wrong results in sliding windows. The buffer was a plain `HashSet` with no per-value multiplicity, so `retract_batch` removed a value entirely when a single occurrence left the window frame, even if other rows in the frame still carried that value. Replace the shared set-based buffer with a per-accumulator `HashMap<Hashable, usize>` count map: `update_batch` reads only the value column and increments counts, `retract_batch` decrements and removes a key only at zero, and `state`/`merge_batch` serialize the distinct keys as a List (unchanged state shape). The other `GenericDistinctBuffer` users (count/sum/ median/variance distinct) are unaffected; only percentile_cont supports retract, so it is the sole accumulator that needed multiplicity tracking. Add regression coverage in aggregate.slt for the plain distinct aggregate and for the sliding-window duplicate-value retract case. Co-authored-by: Claude Code
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #23913 +/- ##
=======================================
Coverage 80.67% 80.67%
=======================================
Files 1094 1094
Lines 371770 371790 +20
Branches 371770 371790 +20
=======================================
+ Hits 299907 299930 +23
+ Misses 53964 53954 -10
- Partials 17899 17906 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Which issue does this PR close?
Rationale for this change
DistinctPercentileContAccumulatorreused the shared set-basedGenericDistinctBuffer, which doesn't fit it: (1) the buffer asserts a single input column butpercentile_contpasses two (value + percentile), so everypercentile_cont(DISTINCT ...)panicked; (2) the buffer is a plainHashSetwith no multiplicity, so sliding-windowretract_batchdropped a value while duplicates were still in the frame.What changes are included in this PR?
HashMap<Hashable, usize>count map:update_batchreads only the value column and increments;retract_batchdecrements and removes a key only at zero;state/merge_batchkeep the same List state shape. OtherGenericDistinctBufferusers are untouched.aggregate.sltfor the plain distinct query and the sliding-window duplicate-retract case.Are these changes tested?
Yes — new regression tests; the full
aggregate.sltsuite passes.Are there any user-facing changes?
percentile_cont(DISTINCT ...)now works instead of panicking, and returns correct results in sliding windows.