You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jayzhan211 (via GitHub)" <gi...@apache.org> on 2026/10/18 10:01:59 UTC

[I] `bit_xor` over a sliding window frame returns 0 instead of NULL when the frame has only NULLs [datafusion]

jayzhan211 opened a new issue, #26470:
URL: https://github.com/apache/datafusion/issues/26470

   ### Describe the bug
   
   When a sliding window frame (one that does not start at `UNBOUNDED PRECEDING`) contains only NULL values, `bit_xor` returns `0` instead of `NULL`. This only happens after the frame has already seen a non-NULL value. The same aggregate over a whole partition returns `NULL` correctly.
   
   ### To Reproduce
   
   ```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;
   ```
   
   ```
   +------+---------+-------+
   | x    | sliding | whole |
   +------+---------+-------+
   | 5    | 5       | 5     |
   | NULL | 0       | NULL  |
   | 6    | 6       | 6     |
   +------+---------+-------+
   ```
   
   ### Expected behavior
   
   `sliding` is `NULL` on the second row, as in `whole`. DuckDB returns `NULL` there.
   
   ### Additional context
   
   `BitXorAccumulator` keeps an `Option` that becomes `Some` on the first non-NULL value. `retract_batch` XORs the leaving values back out, but the state never goes back to `None`. So once every non-NULL value has left the frame, `evaluate` returns `Some(0)`:
   https://github.com/apache/datafusion/blob/3470bd0fbc/datafusion/functions-aggregate/src/bit_and_or_xor.rs#L455-L466
   
   One way to fix it is to count the non-NULL values in the frame and return NULL when the count is zero. `avg` had the same kind of problem in #22139.
   
   ### Willingness to contribute
   
   Feel free to take it!
   


-- 
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: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] `bit_xor` over a sliding window frame returns 0 instead of NULL when the frame has only NULLs [datafusion]

Posted by "cool9850311 (via GitHub)" <gi...@apache.org>.
cool9850311 commented on issue #26470:
URL: https://github.com/apache/datafusion/issues/26470#issuecomment-6248697385

   I'll take it


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] `bit_xor` over a sliding window frame returns 0 instead of NULL when the frame has only NULLs [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 closed issue #26470: `bit_xor` over a sliding window frame returns 0 instead of NULL when the frame has only NULLs
URL: https://github.com/apache/datafusion/issues/26470


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org