james-willis opened a new issue, #7844:
URL: https://github.com/apache/datafusion-comet/issues/7844

   ### Describe the bug
   
   `SparkArraysZipFunc` (`native/spark-expr/src/array_funcs/arrays_zip.rs`) 
builds 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 is lost.
   
   That includes Arrow extension types. `arrays_zip(g, j)` over an array whose 
items are tagged `ARROW:extension:name = geoarrow.wkb` and one whose items are 
tagged `arrow.json` returns `array<struct<g: binary, j: binary>>` with untagged 
children, and the JVM receives plain binary where it expects the extension 
types. The FFI export keeps field metadata (`move_to_spark` has a test for it), 
so the loss is in the expression.
   
   ### Steps to reproduce
   
   No Spark type that Comet ships carries Arrow extension metadata, so the 
shape is a Rust unit test:
   
   ```rust
   let tagged_item = |extension: &str| {
       Arc::new(Field::new("element", DataType::Binary, 
true).with_metadata(HashMap::from([(
           "ARROW:extension:name".to_string(),
           extension.to_string(),
       )])))
   };
   let schema = Schema::new(vec![
       Field::new("g", DataType::List(tagged_item("geoarrow.wkb")), true),
       Field::new("j", DataType::List(tagged_item("arrow.json")), true),
   ]);
   let c = |name: &str| col(name, &schema).unwrap();
   
   let zipped = SparkArraysZipFunc::new(vec![c("g"), c("j")], 
vec!["g".to_string(), "j".to_string()]);
   let DataType::List(item) = zipped.return_field(&schema)?.data_type().clone() 
else { unreachable!() };
   let DataType::Struct(children) = item.data_type().clone() else { 
unreachable!() };
   assert!(children.iter().all(|child| child.metadata().is_empty())); // passes 
today
   ```
   
   ### Expected behavior
   
   Each struct child of the zipped element is the input's item field under its 
Spark name, metadata included, the way a struct constructor keeps the fields it 
packs (apache/datafusion#27502 does this for DataFusion's `named_struct`). The 
evaluated array carries the same fields, because the metadata of nested fields 
is part of the Arrow type and a projection checks its output arrays against the 
declared type.
   
   ### Additional context
   
   Same class as #7768 and #7769; the fix is independent of theirs. 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]

Reply via email to