apache / apache/datafusion

Incorrect query results for GROUP BY with UNIQUE constraint

Open
#21,507 7 comments 0 reactions 1 assignee Claimed by @xiedeyantu 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

```
$ cat ~/groupby_unique_repro.sql
CREATE TABLE t(a INT, b INT, c INT, UNIQUE(a));
INSERT INTO t VALUES (1, 10, 100), (NULL, 20, 200), (NULL, 30, 300);
SELECT a, SUM(c) AS total FROM t GROUP BY a, b ORDER BY a;
DROP TABLE t;

$ cargo run --bin datafusion-cli -- -f ~/groupby_unique_repro.sql
Finished [`dev` profile [unoptimized + debuginfo]](https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles) target(s) in 0.16s
Running `target/debug/datafusion-cli -f /Users/neilconway/groupby_unique_repro.sql`
DataFusion CLI v53.0.0
0 row(s) fetched.
Elapsed 0.044 seconds.

+-------+
| count |
+-------+
| 3 |
+-------+
1 row(s) fetched.
Elapsed 0.034 seconds.

+------+-------+
| a | total |
+------+-------+
| 1 | 100 |
| NULL | 500 |
+------+-------+
2 row(s) fetched.
Elapsed 0.027 seconds.

$ duckdb -f ~/groupby_unique_repro.sql
┌───────┬────────┐
│ a │ total │
│ int32 │ int128 │
├───────┼────────┤
│ 1 │ 100 │
│ NULL │ 200 │
│ NULL │ 300 │
└───────┴────────┘
```

### To Reproduce

_No response_

### Expected behavior

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.