Skip to content

fix: preserve field metadata through arrays_zip - #7845

Draft
james-willis wants to merge 1 commit into
apache:mainfrom
james-willis:arrays-zip-field-metadata
Draft

james-willis wants to merge 1 commit into
apache:mainfrom
james-willis:arrays-zip-field-metadata

Conversation

@james-willis

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #7844

Rationale for this change

SparkArraysZipFunc built the struct fields of the zipped element from each input's element type, once in data_type and again in arrays_zip_inner, so the metadata of the inputs' item fields was lost. That includes Arrow extension types: arrays_zip over an array of geoarrow.wkb-tagged WKB and an array of arrow.json documents handed the JVM an array<struct<...>> whose children were plain binary. The FFI export keeps field metadata, so the loss was in the expression.

What changes are included in this PR?

  • SparkArraysZipFunc::fields takes each input's item field from return_field and uses it whole under its Spark name, nullable as before. data_type builds the struct from those fields, so the default return_field reports the children's metadata.
  • arrays_zip_inner takes the same fields from the input arrays' list types instead of rebuilding them from element types, so the array it returns has the type data_type declares. The metadata of nested fields is part of the Arrow type, and a projection checks its output arrays against the declared type.
  • A Null-typed argument stays a nullable Null child, as before.

How are these changes tested?

New unit test zipped_struct_keeps_the_item_fields in arrays_zip.rs: two list columns whose item fields carry different extension names. It checks that the children of return_field carry each name under the Spark names and are nullable, and that the evaluated array has exactly the declared type. The metadata assertions and the type check fail without the change.

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 types, names and nullability of the zipped struct are unchanged, which the existing sql-tests/expressions/array/arrays_zip.sql cases and CometDecimalPromotionSuite cover.

@github-actions github-actions Bot added bug Something isn't working area:expressions Expression evaluation labels Dec 3, 2026
@james-willis
james-willis marked this pull request as ready for review December 3, 2026 23:51
@james-willis
james-willis force-pushed the arrays-zip-field-metadata branch from 9e4d7e2 to 06018b8 Compare December 4, 2026 07:10
@james-willis
james-willis marked this pull request as draft December 4, 2026 18:43
@james-willis james-willis reopened this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:expressions Expression evaluation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

arrays_zip drops the field metadata of its inputs' elements, including Arrow extension types

1 participant