Jason8Ni opened a new issue, #27729:
URL: https://github.com/apache/datafusion/issues/27729

   ### Describe the bug
   
   Since #27536, struct coercion drops the metadata of a struct child that is 
untyped `NULL` (`DataType::Null`) in every input. This affects a single struct 
argument (`make_array(s)`, `coalesce(NULL, s)`), and several struct arguments 
that are all `NULL` at the same child position (`coalesce(NULL, s, s)`). Only 
the metadata is lost: the child's type and nullability are unchanged. Before 
#27536 the child kept its metadata in these cases.
   
   `merge_struct_fields` in 
`datafusion/expr-common/src/type_coercion/binary.rs` builds each child's 
metadata from its typed contributors and skips `Null`-typed children. When 
every contributor is `Null`, nothing is merged, and `.with_metadata(...)` 
replaces the child's metadata with an empty map.
   
   ### To Reproduce
   
   ```rust
   use arrow::datatypes::{DataType, Field, Fields, Metadata};
   use 
datafusion_expr_common::type_coercion::binary::try_type_union_resolution_with_struct;
   
   let s = DataType::Struct(Fields::from(vec![
       Field::new("a", DataType::Int64, false),
       Field::new("b", DataType::Null, 
true).with_metadata(Metadata::new().with("k", "v")),
   ]));
   let coerced = 
try_type_union_resolution_with_struct(std::slice::from_ref(&s)).unwrap();
   assert_eq!(coerced, vec![s]); // fails: child `b` has no metadata
   ```
   
   The same happens through SQL when a registered table has a struct column `s` 
with child `v: Null` carrying metadata: `SELECT coalesce(NULL, s, s) FROM t` 
returns a struct whose child `v` has empty metadata.
   
   ### Expected behavior
   
   A child that is `NULL` in every input keeps its metadata. When several 
`NULL` inputs disagree, earlier inputs take precedence, matching how typed 
contributors are merged. Children with at least one typed contributor should 
keep ignoring `NULL`-child metadata, as they do today.
   
   ### Additional context
   
   Found while backporting #27536. Callers that use child-field metadata 
(extension types, field IDs, engine-specific tags) lose it silently for these 
shapes.
   


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