james-willis opened a new issue, #7846:
URL: https://github.com/apache/datafusion-comet/issues/7846
### Describe the bug
`MaxMinBy`, `Mode`, `SparkMinMax` and `SparkStructMinMax`
(`native/spark-expr/src/agg_funcs/`) return their value argument's type but
implement only `AggregateUDFImpl::return_type`, so `udaf_default_return_field`
builds the output field from the type alone and the metadata of the value field
is lost.
That includes Arrow extension types. `mode(j)` over a string column tagged
`ARROW:extension:name = arrow.json` returns a plain `Utf8` field, and the same
happens to a `PARQUET:field_id` or any other key on the value column of
`max_by`, `min_by`, `min` and `max`. DataFusion's `first_value` and
`last_value` keep the value field's metadata (`first_last.rs` in
`datafusion-functions-aggregate`); these Comet kernels do not.
Comet's Final and PartialMerge stages take their inputs as `UnboundColumn`s
typed from Spark's declared type, which carry no metadata, so today no
aggregate output carries metadata across the exchange, DataFusion's own
aggregates included. That is a planner question and separate from this one;
this issue is about what the kernels report for the fields they are given.
### Steps to reproduce
No Spark type that Comet ships carries Arrow extension metadata, so the
shape is a Rust unit test:
```rust
let tag = HashMap::from([("ARROW:extension:name".to_string(),
"arrow.json".to_string())]);
let input = Arc::new(Field::new("j", DataType::Utf8,
true).with_metadata(tag));
let field = Mode::new(DataType::Utf8,
false).return_field(&[Arc::clone(&input)])?;
assert!(field.metadata().is_empty()); // passes today
let ordering = Arc::new(Field::new("o", DataType::Int32, true));
let field = MaxMinBy::new_max_by().return_field(&[Arc::clone(&input),
ordering])?;
assert!(field.metadata().is_empty()); // passes today
```
`SparkMinMax` and `SparkStructMinMax` behave the same for a float and a
struct value.
### Expected behavior
`return_field` keeps the type `return_type` reports and the nullability the
function reports today, and carries the value field's metadata whole, as
DataFusion's `first_value` does.
### Additional context
Same class as #7768, #7769 and #7844. `collect_list`, `collect_set` and
`pivot_first` have the related problem on their list item field; they also
build their arrays from the element type, so they are a separate change.
DataFusion 55's own `min` and `max`, which Comet uses for the other types,
implement `return_type` only as well. Found with a geometry UDT mapped to the
`geoarrow.wkb` extension type in a downstream build of Comet.
### Willingness to contribute
I can contribute a fix for this bug independently
--
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]