fornwall opened a new pull request, #25282:
URL: https://github.com/apache/datafusion/pull/25282

   ## Which issue does this PR close?
   
   Closes #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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to