Skip to content

Streaming aggregation produces wrong result with grouping sets #24421

Closed

Description

@2010YOUY01

Describe the bug

Producer in datafusion-cli:

-- data is a test file within datafusion repo
> CREATE EXTERNAL TABLE grouping_set_ordered (
  a0 INTEGER,
  a INTEGER,
  b INTEGER,
  c INTEGER,
  d INTEGER
)
STORED AS CSV
WITH ORDER (c)
LOCATION '/Users/yongting/Code/datafusion-grouping-sets-ordering/datafusion/core/tests/data/window_2.csv'
OPTIONS ('format.has_header' 'true');

> SELECT c
FROM (
  SELECT b, c, grouping(b, c) AS gid
  FROM grouping_set_ordered
  GROUP BY GROUPING SETS ((b, c), (c))
)
ORDER BY c
LIMIT 10;
+---+
| c |
+---+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
+---+
10 row(s) fetched.
Elapsed 0.002 seconds.

Because we have grouping set ((b,c), (c)), each distinct c value should appear twice in the output

D SELECT b,c
  FROM (
      SELECT b, c, grouping(b, c) AS gid
      FROM grouping_set_ordered
      GROUP BY GROUPING SETS ((b, c), (c))
  )
  ORDER BY c
  LIMIT 10;
┌───────┬───────┐
│   b   │   c   │
│ int64 │ int64 │
├───────┼───────┤
│     0 │     0 │
│  NULL │     0 │
│     0 │     1 │
│  NULL │     1 │
│  NULL │     2 │
│     0 │     2 │
│  NULL │     3 │
│     0 │     3 │
│     0 │     4 │
│  NULL │     4 │
├───────┴───────┤
│    10 rows    │
└───────────────┘

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Activity

  1. added theissue type on Aug 17, 2026
  2. self-assigned this
    on Aug 17, 2026
  3. added a commit that references this issue on Aug 19, 2026
    5c846af
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