Jason8Ni opened a new pull request, #27730:
URL: https://github.com/apache/datafusion/pull/27730

   ## Which issue does this PR close?
   
   - Closes #27729.
   
   ## Rationale for this change
   
   Since #27536, struct coercion drops the metadata of a struct child that is 
untyped `NULL` in every input. Examples are `make_array(s)`, `coalesce(NULL, 
s)`, and `coalesce(NULL, s, s)` where `s` has a `Null`-typed child carrying 
metadata. The child's type and nullability are unchanged, but its metadata 
becomes empty, so extension types, field IDs, or other tags on that child are 
lost silently. Before #27536 the child kept its metadata in these cases.
   
   `merge_struct_fields` builds each child's metadata from its typed 
contributors and skips `Null`-typed children. When every contributor is `Null`, 
nothing is merged and the child's metadata is replaced with an empty map.
   
   ## What changes are included in this PR?
   
   - When a child has no typed contributor, `merge_struct_fields` merges the 
metadata of its `NULL` inputs instead. Earlier inputs take precedence, and the 
extension name and extension metadata come together from the first input that 
declares an extension type.
   - Children with at least one typed contributor are unchanged: `NULL`-child 
metadata is still ignored for them, as the existing `coalesce(null_child, 
i32_ext)` case in `test_coalesce_struct_field_metadata` checks.
   
   ## What is the testing strategy for this PR?
   
   - Unit tests in `type_coercion/binary/tests/null_coercion.rs` for 
`try_type_union_resolution_with_struct`. They check that a child that is `NULL` 
in a single input keeps its metadata, that several all-`NULL` inputs merge 
theirs with earlier precedence, and that typed-child metadata still wins over 
`NULL` children in either order.
   - A new `test_coalesce_struct_field_metadata` case, `coalesce(NULL, 
null_child, null_child)`, checks the planned schema and executed array through 
both the simplified and the volatile (native `COALESCE`) paths.
   - The `NULL`-in-every-input tests fail without the fix.
   - `cargo test -p datafusion-expr-common`, `cargo test -p 
datafusion-functions-nested --lib make_array`, `cargo test -p datafusion --test 
core_integration sql::select`, sqllogictests `coalesce`/`struct`/`array`, 
`cargo fmt --all --check`, and clippy (`-p datafusion-expr-common --all-targets 
--all-features`, `-p datafusion --all-targets`) pass.
   
   ## Are there any user-facing changes?
   
   Struct children that are `NULL` in every coerced input keep their field 
metadata again. No API changes.
   
   cc @Xuanwo, since this follows up on #27536.
   


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