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

   ## Which issue does this PR close?
   
   Closes #26296
   
   ## Rationale for this change
   
   In `datafusion/expr-common/src/type_coercion/binary.rs`, during 
`type_union_resolution_coercion` for `(DataType::Struct(lhs), 
DataType::Struct(rhs))`, each field's coerced type was computed by matching 
fields by name, but the field nullability was derived by positionally zipping 
`lhs` and `rhs`:
   
   ```rust
   let orig_fields = std::iter::zip(lhs.iter(), rhs.iter());
   ```
   
   When two structs contain the same set of field names in differing order 
(e.g. `lhs = { a: NOT NULL, b: NOT NULL }` and `rhs = { b: NULL, a: NOT NULL 
}`), this positional zipping paired `lhs.a` with `rhs.b`, resulting in field 
`a` being marked nullable while field `b` was marked non-nullable.
   
   ## What changes are included in this PR?
   
   - Replaced positional field zipping with name-matched field resolution in 
`type_union_resolution_coercion`.
   - Combined field nullability is derived strictly from corresponding 
name-matched field pairs (`lhs.is_nullable() || rhs.is_nullable()`).
   - Added regression tests covering reordered struct fields and type widening 
in `datafusion/expr-common/src/type_coercion/binary/tests/comparison.rs`.
   
   ## Are these changes tested?
   
   Yes, unit test `test_type_union_resolution_struct_reordered_nullability` 
added and all 240 unit tests in `datafusion-expr-common` pass green locally.
   
   ## Are there any user-facing changes?
   
   No breaking changes. Fixes a type correctness bug where reordered structs 
produced wrong field nullabilities during type union resolution.


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