Skip to content

GROUPING SETS (()) returns no rows on empty input #22040

Closed

Description

@xiedeyantu

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

Activity

  1. added theissue type on May 6, 2026
  2. xiedeyantu commented on May 6, 2026

    @xiedeyantu
    MemberAuthor

    take

  3. added a commit that references this issue on May 12, 2026
    526ed6c
  4. added a commit that references this issue on May 14, 2026
    cc5e925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions