fix: handle NULLs in sliding SUM(DISTINCT) window frames#22755
Open
kumarUjjawal wants to merge 2 commits into
Open
fix: handle NULLs in sliding SUM(DISTINCT) window frames#22755kumarUjjawal wants to merge 2 commits into
kumarUjjawal wants to merge 2 commits into
Conversation
kosiew
approved these changes
Jun 5, 2026
Contributor
There was a problem hiding this comment.
@kumarUjjawal
Thanks for the fix. This looks good and I only have one small suggestion.
| if *cnt == 0 { | ||
| // first occurrence in window | ||
| self.sum = self.sum.wrapping_add(v); | ||
| if arr.null_count() == 0 { |
Contributor
There was a problem hiding this comment.
Nice cleanup overall. One small thought: the NULL-aware iteration logic looks very similar between update_batch and retract_batch. Would it make sense to extract a small helper that keeps the current no-null fast path and accepts the value operation, something like apply_valid_values(values, Self::update_value) and apply_valid_values(values, Self::retract_value)?
That would keep the invariant that only valid slots affect counts and sum in one place and help avoid the two paths drifting apart over time.
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
SUM(DISTINCT)over bounded/sliding window frames did not handleNULLvalues correctly.It could read values from null slots in the Arrow buffer, and it returned
0instead ofNULLwhen a frame had no non-null values.What changes are included in this PR?
NULLrows in slidingSUM(DISTINCT)updateNULLrows in slidingSUM(DISTINCT)retractNULLwhen the frame has no non-null distinct valuesNULLAre these changes tested?
Yes
Are there any user-facing changes?
SUM(DISTINCT)over bounded/sliding window frames now handlesNULLvalues correctly:NULLinputs are ignoredNULLinstead of0