Describe the bug
GROUP BY (and SELECT DISTINCT) over a group key whose type contains a zero-field struct (DataType::Struct(Fields::empty())) panics when the aggregate emits.
A zero-field struct array has no child to derive its length from, so arrow-rs refuses StructArray::try_new for it. The group-value emit path rebuilds the key column with that constructor and unwraps the resulting error.
To Reproduce
$ datafusion-cli -c "select arrow_cast(null, 'Struct()') as s, count(*) from (values (1),(2),(3)) group by 1;"
DataFusion CLI v55.1.0
thread 'tokio-rt-worker' panicked at datafusion/physical-plan/src/aggregates/group_values/multi_group_by/row_backed.rs:225:14:
dictionary re-encode during emit: ArrowError(InvalidArgumentError("use StructArray::try_new_with_length or StructArray::new_empty_fields to create a struct array with no fields so that the length can be set correctly"), Some(""))
Error: Join Error
caused by
External error: task 63 panicked with message "dictionary re-encode during emit: ..."
Same panic for SELECT DISTINCT:
select distinct arrow_cast(null, 'Struct()') as s from (values (1),(2));
and when the zero-field struct is nested inside the key rather than being the whole key:
select named_struct('a', column1, 'z', arrow_cast(null, 'Struct()')) as s, count(*)
from (values (1),(2)) group by 1;
Expected behavior
The query returns its groups. A zero-field struct is a valid Arrow type and carries one bit per row (null or not), so it should group like any other key.
Additional context
Reproduced on main at 15f32dd.
Describe the bug
GROUP BY(andSELECT DISTINCT) over a group key whose type contains a zero-field struct (DataType::Struct(Fields::empty())) panics when the aggregate emits.A zero-field struct array has no child to derive its length from, so arrow-rs refuses
StructArray::try_newfor it. The group-value emit path rebuilds the key column with that constructor and unwraps the resulting error.To Reproduce
Same panic for
SELECT DISTINCT:and when the zero-field struct is nested inside the key rather than being the whole key:
Expected behavior
The query returns its groups. A zero-field struct is a valid Arrow type and carries one bit per row (null or not), so it should group like any other key.
Additional context
Reproduced on
mainat 15f32dd.