fix: make_array accepts inputs differing only in nested-field nullability#22658
Open
schenksj wants to merge 1 commit into
Open
fix: make_array accepts inputs differing only in nested-field nullability#22658schenksj wants to merge 1 commit into
schenksj wants to merge 1 commit into
Conversation
…lity `make_array` panicked with "Arrays with inconsistent types passed to MutableArrayData" when combining values whose types are identical except for the nullability of a nested field (e.g. a struct field that is non-nullable when built from a literal but nullable when read from a column). This blocks native execution of plans that construct structs from multiple sources (Delta Lake CDC writes, UNION within arrays). Following the precedent of Spark, Postgres, and Arrow's own `concat`, relax the strict element-type equality by widening nullable flags to `true` at every nesting level: - `array_array` now computes a merged element type that is a supertype of all arguments (OR-ing nullable flags via `Field::try_merge`) and cheaply casts each argument up to it before building the list, so `MutableArrayData` no longer sees inconsistent types. - `coerce_types_inner` widens the per-argument struct types produced by `try_type_union_resolution_with_struct` to a single common type so the declared return type matches the value produced at runtime. Adds a unit test reproducing the original panic and sqllogictest coverage for `make_array` over (nested) structs. Closes apache#22366 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
make_arraypanics withArrays with inconsistent types passed to MutableArrayDatawhen combining values whose types are identical except for the nullability of a nested field — for example a struct field that is non-nullable when constructed from a literal but nullable when read from a column.This blocks native execution of plans that construct structs from multiple sources (Delta Lake CDC writes,
UNIONwithin arrays), forcing workarounds that sacrifice performance.Spark, Postgres, and Arrow's own
concatall handle this by widening nullable flags rather than enforcing strict type equality. This PR bringsmake_arrayin line with that precedent: inputs that differ only in nested-field nullability are accepted, and the result widens nullable flags totrueat every nesting level.What changes are included in this PR?
merge_nullability, which OR-s nullable flags at every nesting level (struct fields, list elements, ...) using Arrow'sField::try_merge, and returnsNone(preserving prior behavior) for structurally-incompatible inputs.array_array(the runtime shared by bothmake_arrayand Spark'sarray) computes a merged element type that is a supertype of all arguments and cheaply casts each argument up to it before building the list, soMutableArrayDatano longer sees inconsistent types.coerce_types_innerwidens the per-argument struct types produced bytry_type_union_resolution_with_structto a single common type, so the declared return type matches the value produced at runtime.Are these changes tested?
Yes:
make_array_relaxes_nested_field_nullability) reproduces the original panic at themake_array_innerboundary and asserts it now succeeds.array/make_array.sltformake_arrayover flat and nested structs.Note: the SQL planner already normalizes nested-field nullability for struct construction from SQL literals/columns, so the panic is reached from sources with declared non-null nested schemas (e.g. Delta Lake CDC); the unit test exercises that path directly.
Are there any user-facing changes?
make_array(and Sparkarray) now succeed on inputs that previously panicked. There are no breaking API changes; the result type simply widens nested nullable flags where inputs disagree.