Repository navigation
Commit 348553b
authored
fix: support zero-field struct group keys in aggregate emit (apache#25282)
## Which issue does this PR close?
Closes apache#25281.
## Rationale for this change
`GROUP BY` and `SELECT DISTINCT` over a group key whose type contains a
zero-field struct (`Struct()`) panicked when the aggregate emitted:
```sql
select arrow_cast(null, 'Struct()') as s, count(*) from (values (1),(2),(3)) group by 1;
-- thread 'tokio-rt-worker' panicked ... dictionary re-encode during emit:
-- InvalidArgumentError("use StructArray::try_new_with_length or StructArray::new_empty_fields ...")
```
The same panic hit `SELECT DISTINCT` and keys where the empty struct is
nested inside another struct. A zero-field struct is a valid Arrow type
and should group like any other key.
## What changes are included in this PR?
`encode_array_if_necessary` in `group_values/row.rs` rebuilt every
struct column with `StructArray::try_new`, which arrow rejects for zero
fields since there is no child column to derive the length from. It now
uses `StructArray::try_new_with_length` with the source array's length,
so zero-field structs are rebuilt like any other struct. This function
is shared by `GroupValuesRows` and the row-backed `GroupColumn`, so both
paths are covered.
## What is the testing strategy for this PR?
Three new `sqllogictest` cases at the end of `struct.slt` (whole-key,
`DISTINCT`, and nested inside `named_struct`). All three panicked before
the fix and pass after it.
## Are there any user-facing changes?
No, other than the panic being fixed.
Signed-off-by: Fredrik Fornwall <[email protected]>1 parent f4ca8a8 commit 348553b
2 files changed
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
| 319 | + | |
| 320 | + | |
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
| 324 | + | |
323 | 325 | | |
324 | 326 | | |
325 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1872 | 1872 | | |
1873 | 1873 | | |
1874 | 1874 | | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
0 commit comments