Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion datafusion/physical-plan/src/aggregates/group_values/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ pub(crate) fn encode_array_if_necessary(
})
.collect::<Result<Vec<_>>>()?;

Ok(Arc::new(StructArray::try_new(
// A zero-field struct has no child to infer the length from.
Ok(Arc::new(StructArray::try_new_with_length(
expected_fields.clone(),
arrays,
struct_array.nulls().cloned(),
struct_array.len(),
)?))
}
(DataType::List(expected_field), &DataType::List(_)) => {
Expand Down
18 changes: 18 additions & 0 deletions datafusion/sqllogictest/test_files/struct.slt
Original file line number Diff line number Diff line change
Expand Up @@ -1752,3 +1752,21 @@ limit 2;

statement ok
drop table list_cast_limit;

# GROUP BY / DISTINCT over a zero-field struct key must not panic on emit
query ?I
select arrow_cast(null, 'Struct()') as s, count(*) from (values (1),(2),(3)) group by 1;
----
NULL 3

query ?
select distinct arrow_cast(null, 'Struct()') as s from (values (1),(2));
----
NULL

query ?I rowsort
select named_struct('a', column1, 'z', arrow_cast(null, 'Struct()')) as s, count(*)
from (values (1),(2),(1)) group by 1;
----
{a: 1, z: NULL} 2
{a: 2, z: NULL} 1