choksi2212 opened a new pull request, #26482:
URL: https://github.com/apache/datafusion/pull/26482

   ## Which issue does this PR close?
   
   - Closes #26470
   
   ## Rationale for this change
   
   `bit_xor` over a sliding window frame returned `0` instead of `NULL` once 
every non-NULL value had left the frame:
   
   ```sql
   SELECT x,
     bit_xor(x) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND CURRENT ROW) AS 
sliding,
     bit_xor(x) OVER (PARTITION BY i) AS whole
   FROM (VALUES (1, 5), (2, NULL), (3, 6)) t(i, x)
   ORDER BY i;
   ```
   
   gave `0` on the second row for `sliding`, while `whole` (and DuckDB) give 
`NULL`. `BitXorAccumulator::retract_batch` XORs the leaving values back out, so 
the running `Option` stays `Some(0)` when the frame empties instead of 
returning to `None`. The window machinery only calls `retract_batch` when the 
accumulator opts in via `supports_retract_batch`, and `bit_xor` is the only one 
of the bit aggregates that does, which is why the wrong `0` was specific to it.
   
   ## What changes are included in this PR?
   
   `BitXorAccumulator` now also keeps a count of the non-NULL values currently 
in the aggregate, maintained in the opposite direction by `retract_batch`, and 
`evaluate` yields `NULL` when the count is zero. This is the same shape `avg` 
uses to handle sliding frames (#22139). A frame holding two equal values still 
correctly produces `0`, because that is a real aggregate result rather than an 
empty one.
   
   ## What is the testing strategy for this PR?
   
   - Accumulator-level unit tests in `bit_and_or_xor.rs`: retracting everything 
that was added yields `NULL`, retracting an all-NULL batch changes nothing, and 
values entering an emptied frame aggregate from scratch.
   - End-to-end window cases in a new `bit_xor_sliding_window.slt`, following 
`array_agg_sliding_window.slt`: the issue repro, a wider frame that becomes 
all-NULL after the 7 leaves, leading-NULL frames, a legitimate-zero pin (`10 ^ 
10`), and unbounded-frame regression rows.
   
   ## Are there any user-facing changes?
   
   `bit_xor` over a sliding frame whose values have all been retracted now 
returns `NULL` instead of `0`. No public API changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to