1fanwang opened a new issue, #25766:
URL: https://github.com/apache/datafusion/issues/25766

   ### Describe the bug
   
   `PARTITION BY` in a window function puts `0.0` and `-0.0` in separate 
partitions. `GROUP BY`, `DISTINCT` and joins treat them as the same value (see 
`negative_zero.slt`), so window results disagree with the rest of the engine.
   
   ### To Reproduce
   
   ```sql
   > SELECT a, row_number() OVER (PARTITION BY a) AS rn FROM (VALUES (0.0), 
(-0.0)) t(a);
   +------+----+
   | a    | rn |
   +------+----+
   | -0.0 | 1  |
   | 0.0  | 1  |
   +------+----+
   
   > SELECT count(*) FROM (SELECT a FROM (VALUES (0.0), (-0.0)) t(a) GROUP BY 
a);
   +----------+
   | count(*) |
   +----------+
   | 1        |
   +----------+
   ```
   
   ### Expected behavior
   
   One partition, so the two rows get row numbers 1 and 2, matching `GROUP BY`.
   
   ### Additional context
   
   This shows up in `INTERSECT ALL` / `EXCEPT ALL` once they are planned with 
`row_number() OVER (PARTITION BY <all columns>)` (#25742):
   
   ```sql
   SELECT a FROM (VALUES (0.0), (-0.0)) t(a) INTERSECT ALL SELECT a FROM 
(VALUES (0.0)) s(a); -- 2 rows, expected 1
   SELECT a FROM (VALUES (0.0), (-0.0)) t(a) EXCEPT ALL SELECT a FROM (VALUES 
(0.0)) s(a);    -- 0 rows, expected 1
   ```
   
   Reported by @kita-renji in 
https://github.com/apache/datafusion/pull/25742#pullrequestreview-5324718949. I 
haven't traced it fully, but partition boundaries come from arrow's `partition` 
kernel (`evaluate_partition_ranges`), which I think compares floats by total 
order, where `-0.0 != 0.0`.
   


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