datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

Execution panic for valid 64-column GROUPING SETS

Open alexandrefimov opened this issue 1 month ago • 2 comments

Describe the bug

A GROUPING SETS query with 64 distinct grouping columns can panic during execution, even when no grouping set is repeated.

group_id_array packs the duplicate ordinal using ordinal << n. With 64 columns and ordinal zero, this evaluates 0u64 << 64 and panics in a checked build. The layout itself fits UInt64.

To reproduce

Generate the SQL below and run its output in a debug DataFusion CLI:

n = 64
cols = ", ".join(f"c{i} INTEGER" for i in range(n))
keys = ", ".join(f"c{i}" for i in range(n))
row = ", ".join(str(i + 1) for i in range(n))
print(f"CREATE TABLE wide_keys ({cols});")
print(f"INSERT INTO wide_keys VALUES ({row});")
print(f"SELECT COUNT(*) FROM wide_keys "
      f"GROUP BY GROUPING SETS (({keys}), ());")

Expected behavior

The query should return two rows, each with COUNT(*) = 1. Layouts requiring more than 64 total bits should continue to return NotImplemented.

Additional context

The shift overflow is confirmed by focused regression tests on commit 102a1628592121d96bfe3d09d80e63180eef288a.

alexandrefimov avatar Oct 08 '26 09:10 alexandrefimov

take

siddubakka avatar Oct 08 '26 10:10 siddubakka

A fix is already in PR #26136. Thanks for offering to help.

alexandrefimov avatar Oct 08 '26 14:10 alexandrefimov