Describe the bug
When a query uses GROUP BY GROUPING SETS(()) and the input relation is empty, DataFusion returns 0 rows. This is incorrect.
According to SQL semantics, the empty grouping set () represents a global aggregate, so it should still produce exactly one output row even when there are no input rows.
In practice, this affects queries such as:
SELECT SUM(empno)
FROM emp
WHERE false
GROUP BY GROUPING SETS(());
The current result is an empty result set, but it should return one row with NULL for SUM(empno).
To Reproduce
Steps to reproduce the behavior:
Create a table and insert data.
Run a query with WHERE false so the input becomes empty.
Use GROUP BY GROUPING SETS(()).
Example:
CREATE TABLE emp (
empno INT PRIMARY KEY,
ename VARCHAR(10) NOT NULL,
job VARCHAR(10),
mgr INT,
hiredate DATE,
sal DECIMAL(10,2),
comm DECIMAL(10,2),
deptno INT
);
INSERT INTO emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO) VALUES
(7369, 'SMITH', 'CLERK', 7902, '1980-12-17', 800.00, NULL, 20);
SELECT SUM(empno)
FROM emp
WHERE false
GROUP BY GROUPING SETS(());
Returns:
+----------------+
| sum(emp.empno) |
+----------------+
+----------------+
0 row(s) fetched.
Expected behavior
Returns:
+----------------+
| sum(emp.empno) |
+----------------+
| NULL |
+----------------+
1 row(s) fetched.
Additional context
No response
Describe the bug
When a query uses GROUP BY GROUPING SETS(()) and the input relation is empty, DataFusion returns 0 rows. This is incorrect.
According to SQL semantics, the empty grouping set () represents a global aggregate, so it should still produce exactly one output row even when there are no input rows.
In practice, this affects queries such as:
The current result is an empty result set, but it should return one row with NULL for SUM(empno).
To Reproduce
Steps to reproduce the behavior:
Create a table and insert data.
Run a query with WHERE false so the input becomes empty.
Use GROUP BY GROUPING SETS(()).
Example:
Returns:
Expected behavior
Returns:
Additional context
No response