Repository navigation
fix: preserve field metadata through max_by, min_by, mode, min and max - #7847
Draft
james-willis wants to merge 1 commit into
Draft
james-willis wants to merge 1 commit into
james-willis wants to merge 1 commit into
Conversation
james-willis
marked this pull request as ready for review
December 3, 2026 23:51
james-willis
force-pushed
the
aggregate-return-field
branch
from
December 4, 2026 07:10
f999322 to
2431086
Compare
james-willis
marked this pull request as draft
December 4, 2026 18:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #7846
Rationale for this change
MaxMinBy,Mode,SparkMinMaxandSparkStructMinMaxreturn their value argument's type but implement onlyreturn_type, so the defaultreturn_fieldbuilds the output field from the type alone and the value field's metadata, extension types included, is lost. DataFusion'sfirst_valueandlast_valuekeep it; these kernels should report the same field.What changes are included in this PR?
return_fieldon the four aggregates: the fieldudaf_default_return_fieldbuilt, with the function's name, the typereturn_typereports and nullable, plus the value argument's metadata, cloned whole.DataType, which already embeds nested fields, so for a struct value the output array has exactly the declared type.Comet's Final and PartialMerge stages take their inputs as
UnboundColumns typed from Spark's declared type, without metadata, so the output of a two-stage aggregate does not carry the tag to the JVM yet, for these kernels or for DataFusion's own. Carrying it across the exchange is a planner change and is out of scope here.How are these changes tested?
New unit tests in each file.
return_field_keeps_value_metadata,return_field_keeps_input_metadata(twice) andreturn_field_keeps_struct_metadatacheck the returned field's name, type, nullability and metadata, and fail without the change.struct_value_keeps_nested_metadatainmax_min_by.rsand the accumulator part ofreturn_field_keeps_struct_metadatacheck that the array an accumulator produces for a struct value with a tagged child has exactly the declared type; they pass before and after and document the contract.cargo test -p datafusion-comet-spark-expr,cargo clippy -p datafusion-comet-spark-expr --all-targets -- -D warningsandcargo fmt --all -- --checkpass locally.There is no new Spark SQL test because no Spark type that Comet ships carries Arrow extension metadata. The aggregates' values, types and nullability are unchanged, which the existing suites cover.