Skip to content

fix: Return NULL for empty BIT_XOR sliding windows - #26095

Draft
geoffreyclaude wants to merge 1 commit into
apache:mainfrom
geoffreyclaude:fix/sliding-bit-xor-empty-frame
Draft

geoffreyclaude wants to merge 1 commit into
apache:mainfrom
geoffreyclaude:fix/sliding-bit-xor-empty-frame

Conversation

@geoffreyclaude

@geoffreyclaude geoffreyclaude commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

No existing issue. The SQL regression below reproduces the bug on current main.

Rationale for this change

BIT_XOR returns 0 instead of NULL after the last non-null value leaves a sliding window. For values 7, NULL, 9, a window containing only the preceding row produces NULL, 7, 0; the correct results are NULL, 7, NULL.

SELECT id,
       bit_xor(v) OVER (
           ORDER BY id ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING
       ) AS x
FROM (VALUES (1, CAST(7 AS BIGINT)),
             (2, CAST(NULL AS BIGINT)),
             (3, CAST(9 AS BIGINT))) AS t(id, v)
ORDER BY id;

What changes are included in this PR?

Add a sliding BIT_XOR accumulator that tracks the remaining non-null count alongside the XOR value. This distinguishes an empty aggregate from a nonempty aggregate whose values cancel to zero.

The sliding factory supplies this accumulator. The ordinary accumulator no longer advertises retraction support. Ordinary scalar and grouped aggregation retain their existing one-field state and groups implementation.

What is the testing strategy for this PR?

Rust tests cover the public sliding factory's zero/NULL transitions, merging partial states with correct input counts, and the ordinary/DISTINCT factory contracts.

bit_xor_sliding_window.slt exercises all eight integer types across batch boundaries, including empty and all-null frames, actual zero, and cancelling values.

Are there any user-facing changes?

Sliding BIT_XOR windows return NULL after all non-null inputs leave. Callers that need retraction should request the sliding accumulator; the ordinary factory reports that it does not support retraction.

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

codecov-commenter commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.51908% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.72%. Comparing base (db83fcc) to head (436baf5).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...tafusion/functions-aggregate/src/bit_and_or_xor.rs 72.51% 6 Missing and 30 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main   #26095     +/-   ##
=========================================
  Coverage   82.72%   82.72%             
=========================================
  Files        1147     1147             
  Lines      448179   449287   +1108     
  Branches   448179   449287   +1108     
=========================================
+ Hits       370754   371674    +920     
- Misses      54895    54935     +40     
- Partials    22530    22678    +148     

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

@geoffreyclaude
geoffreyclaude force-pushed the fix/sliding-bit-xor-empty-frame branch from aef243b to 436baf5 Compare October 7, 2026 07:03
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.

2 participants