apache / apache/datafusion

Group by duplicate GROUPING SETS returns wrong result

Open
#5,672 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

**Describe the bug**

**To Reproduce**

```rust
let sql = "SELECT c1, avg(c12) FROM aggregate_test_100 GROUP BY GROUPING SETS((c1),(c1),())";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+----+-----------------------------+",
"| c1 | AVG(aggregate_test_100.c12) |",
"+----+-----------------------------+",
"| | 0.5089725099127211 |",
"| a | 0.48754517466109415 |",
"| b | 0.41040709263815384 |",
"| c | 0.6600456536439784 |",
"| d | 0.48855379387549824 |",
"| e | 0.48600669271341534 |",
"| a | 0.48754517466109415 |",
"| b | 0.41040709263815384 |",
"| c | 0.6600456536439784 |",
"| d | 0.48855379387549824 |",
"| e | 0.48600669271341534 |",
"+----+-----------------------------+",
];

```

the actual returned is:

```rust

"+----+-----------------------------+",
"| c1 | AVG(aggregate_test_100.c12) |",
"+----+-----------------------------+",
"| | 0.5089725099127211 |",
"| a | 0.48754517466109415 |",
"| b | 0.41040709263815384 |",
"| c | 0.6600456536439784 |",
"| d | 0.48855379387549824 |",
"| e | 0.48600669271341534 |",
"+----+-----------------------------+",
```

**Expected behavior**

**Additional context**

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported query through the Rust execute_to_batches(&ctx, sql) entry point and compare its batches with the expected output. Trace the GROUPING SETS handling and add or update coverage for GROUPING SETS((c1),(c1),()); done means both occurrences of the grouped rows are returned along with the empty grouping set.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.