james-willis opened a new pull request, #7851: URL: https://github.com/apache/datafusion-comet/pull/7851
## Which issue does this PR close? Closes #7850 ## Rationale for this change The collect aggregates and `pivot_first` built their list item field from the element type alone, in the output field, the state field and the arrays the accumulators produce, so the metadata of the collected value's field, extension types included, was lost. The item field should be the value's field whole, and every list the aggregate builds has to carry it, because the metadata of a nested field is part of the Arrow type and the output batch is checked against the declared schema. ## What changes are included in this PR? - `CometCollectList` and `CometCollectSet` implement `return_field`: a list whose item is the argument's field renamed to the list item name and nullable. `state_fields` declares the state as that same list type instead of taking it from `datafusion_spark`, and `default_value` builds the empty list with the declared item. - The grouped accumulators take their item field from `AccumulatorArgs::return_field` and build every list, state and `convert_to_state` output from it. The ungrouped path still runs `datafusion_spark`'s accumulators, wrapped in `RelabelledList`, which gives the lists they return the declared item field without copying the values. - `SparkPivotFirst` implements `return_field` with the value argument's metadata on the item, and its accumulators build the result list from the item field in `AccumulatorArgs::return_field`. Its state slots are plain value columns and are unchanged. - `agg_funcs::list_item` reads the item field out of a declared `List` type for both files. As for #7847, Comet's Final and PartialMerge stages take their inputs as `UnboundColumn`s typed from Spark's declared type, without metadata, so a two-stage aggregate does not hand the tag to the JVM yet. That is a planner change and out of scope here. ## How are these changes tested? New unit tests through the `AggregateUDFImpl` API. `declared_fields_keep_item_metadata` checks `return_field`, `state_fields` and `default_value` for both collect functions, and `return_field_keeps_value_metadata` checks `return_field` and both accumulators for `pivot_first`; run against the old implementation, both fail at the first metadata assertion. `accumulators_produce_the_declared_list_type` checks that the grouped and ungrouped collect accumulators' results and states have exactly the declared list type, tagged item included; it passes before and after, since the old code was consistently untagged, and pins the contract the first test now makes tagged. The existing collect and pivot_first tests are unchanged apart from building accumulators with an item field. `cargo test -p datafusion-comet-spark-expr`, `cargo clippy -p datafusion-comet-spark-expr --all-targets -- -D warnings` and `cargo fmt --all -- --check` pass locally. There is no new Spark SQL test because no Spark type that Comet ships carries Arrow extension metadata. The aggregates' values and list types are unchanged, which the existing suites cover. -- 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]
