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

   ### Describe the bug
   
   `ListExtract` and `GetArrayStructFields` 
(`native/spark-expr/src/array_funcs/`) and `GetStructField` and 
`CreateNamedStruct` (`native/spark-expr/src/struct_funcs/`) implement 
`data_type` and `nullable` but not `return_field`. The `PhysicalExpr` default 
builds the output `Field` from the type alone, so the metadata of the list item 
field or struct field being read, and of the children packed into a struct, is 
lost.
   
   That includes Arrow extension types. `element_at(arr, i)` over a `List` 
whose item field is tagged `ARROW:extension:name = geoarrow.wkb` returns a 
plain `Binary` column; `s.g` over a struct whose field `g` carries the tag does 
the same; `struct(g)` builds a struct whose field has no metadata. The FFI 
export keeps field metadata (`move_to_spark` has a test for it), so the loss is 
in the expression's output field.
   
   Spark's `array()` lowers to DataFusion's `make_array`, which drops the item 
field's metadata on its side (apache/datafusion#21982, partially fixed by 
apache/datafusion#27502), so `element_at(array(g1, g2), i)` loses the tag 
twice. Fixing the four Comet expressions is independent of that.
   
   ### Steps to reproduce
   
   No Spark type that Comet ships carries Arrow extension metadata, so the 
shape is a Rust unit test:
   
   ```rust
   let tagged = |name: &str| {
       Field::new(name, DataType::Binary, true).with_metadata(HashMap::from([(
           "ARROW:extension:name".to_string(),
           "geoarrow.wkb".to_string(),
       )]))
   };
   let schema = Schema::new(vec![
       tagged("g"),
       Field::new("s", DataType::Struct(vec![tagged("g")].into()), true),
       Field::new(
           "arr",
           DataType::List(Arc::new(Field::new(
               "item",
               DataType::Struct(vec![tagged("g")].into()),
               true,
           ))),
           true,
       ),
   ]);
   let c = |name: &str| col(name, &schema).unwrap();
   
   // s.g: the struct field is tagged, the result is not
   let field = GetStructField::new(c("s"), 0);
   assert!(field.return_field(&schema)?.metadata().is_empty()); // passes today
   
   // arr.g over a list of structs: the item's field is tagged, the result's 
item is not
   let items = GetArrayStructFields::new(c("arr"), 0);
   let DataType::List(item) = items.return_field(&schema)?.data_type().clone() 
else { unreachable!() };
   assert!(item.metadata().is_empty()); // passes today
   
   // struct(g): the child field is tagged, the struct's field is not
   let packed = CreateNamedStruct::new(vec![c("g")], vec!["g".to_string()]);
   let DataType::Struct(struct_fields) = 
packed.return_field(&schema)?.data_type().clone() else { unreachable!() };
   assert!(struct_fields[0].metadata().is_empty()); // passes today
   ```
   
   `ListExtract` behaves like `GetStructField` for the list item field; its 
constructor also takes a `QueryContextMap`, which is why it is left out of the 
snippet.
   
   ### Expected behavior
   
   `return_field` carries the metadata of the field the expression reads: the 
list item field for `ListExtract` and `GetArrayStructFields`, the struct field 
for `GetStructField`, and the children's own fields, metadata included, for 
`CreateNamedStruct`.
   
   ### Additional context
   
   Same class as #7768 for `CASE WHEN` and `IF`. Wherobots hit both with 
GeoArrow-tagged geometry columns.
   


-- 
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