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

   ## Which issue does this PR close?
   
   - Closes #<issue-number>
   
   ## Rationale for this change
   
   `GROUPING SETS (())` should return one row even when the input is empty, 
because the empty grouping set represents a global aggregate. In the current 
behavior, queries such as `WHERE false GROUP BY GROUPING SETS(())` can 
incorrectly be optimized into an empty result, returning 0 rows instead of the 
expected 1 row. This change fixes that SQL semantics bug.
   
   ## What changes are included in this PR?
   
   This PR makes two related fixes:
   
   1. It updates the empty-relation propagation rule so aggregates with an 
empty grouping set are not eliminated.
   2. It updates the grouped hash aggregate execution path so empty grouping 
sets are initialized correctly and still produce output on empty input.
   
   It also adds regression coverage in `grouping.slt` for:
   
   - `GROUPING SETS (())` on empty input
   - `COUNT(*)` on empty input
   - mixed grouping sets where only the empty grouping set should produce a row
   
   ## Are these changes tested?
   
   Yes. I ran:
   
   - `cargo test -p datafusion-sqllogictest -- grouping`
   - cargo test -p datafusion-optimizer -- propagate_empty
   - `cargo clippy --tests --all-features -p datafusion-physical-plan -p 
datafusion-optimizer -- -D warnings`
   - `cargo fmt --check`
   
   ## Are there any user-facing changes?
   
   Yes. Queries using `GROUPING SETS (())`, and other grouping-set forms that 
include the empty set such as `ROLLUP` and `CUBE`, will now return the correct 
row on empty input instead of incorrectly returning no rows.


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