Repository navigation
[den-55] fix: reconcile Struct fields during type coercion (#27536) - #221
Merged
Merged
Conversation
Related to apache#21982. This is the lower layer of the constructor metadata work in apache#27502; it fixes shared Struct coercion independently of constructor field propagation. Struct arguments can be assigned different child nullability or metadata even when a function needs one common type. For example, COALESCE with a non-nullable child in one argument and a nullable child in another can fail with `Cannot cast nullable struct field 'v' to non-nullable field`. Use one Struct reconciliation path behind the existing coercion entry points. It preserves existing field-order choices, merges child nullability and metadata by field name, ignores untyped NULL contributors, and recurses into directly nested Structs. Changed child types lose their extension annotations while retaining ordinary metadata; conflicting surviving extension names produce a planning error. Route the existing array coercion adapter through that result so it cannot swallow a metadata error and retry storage-only inference. Keep its function-specific error for ordinary unification failures and its public signature. Remove both extension metadata keys directly at the call site, adding `arrow-schema` as a direct workspace dependency of `datafusion-expr-common` at the existing pinned Arrow version (`60.1.0`, `default-features = false`). SQL regressions over registered Struct columns check planned schemas and executed arrays—types, metadata, values, and root/child NULL validity—across COALESCE's simplified CASE path, a volatile expression that retains native COALESCE execution, and `make_array`. They cover extension preservation at unchanged child types, extension stripping on child type promotion, ordinary metadata precedence, ignoring untyped NULL-child metadata while widening child nullability, top-level and nested field-order rules, and conflicting child extension planning errors. SQLLogicTests cover pure-SQL Struct COALESCE coercion and planning errors when comma-containing field names differ. A focused unit test retains coverage for the public array-coercion adapter's caller-named error contract. The lower layer at `f03a6ec95` passed formatting, all-target/all-feature clippy, 62 coercion tests, 162 nested-function tests, 20 SELECT tests, `coalesce.slt`/`struct.slt`, and the extended workspace suite (13,453 tests passed, 8 ignored, and 307 SQLLogicTest files completed). Struct arguments resolve to one compatible type, including child nullability and metadata. COALESCE accepts the nullable-child case above. Conflicting surviving child extension names fail during planning instead of being silently discarded by the array coercion fallback. Port `datafusion_common::metadata::coerced_fields_metadata` and its unit tests verbatim from apache#24865, which this change calls but the fork lacks. Nothing else calls it yet, so COALESCE, NVL2, and CASE return-field metadata behavior is unchanged. Adapt the new tests to arrow 59, which has no `arrow::datatypes::Metadata` builder: `select.rs` aliases it to `HashMap<String, String>` with a small `with` helper, and the `make_array` unit test builds `HashMap`s directly. The coercion result calls `FieldMetadata::to_hashmap()` because arrow 59's `Field::with_metadata` takes a `HashMap`. Keep the existing `plan_err` import in `make_array.rs`, which the fork still uses. Conflicts in `select.rs` and `coalesce.slt` came from intermediate upstream tests (apache#27143 and the volatile COALESCE tests for apache#25477); only the tests added by this change are kept. (cherry picked from commit 04b9108)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## den-55 #221 +/- ##
========================================
Coverage 81.27% 81.28%
========================================
Files 1111 1111
Lines 390309 390505 +196
Branches 390309 390505 +196
========================================
+ Hits 317233 317429 +196
+ Misses 54460 54458 -2
- Partials 18616 18618 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cargo audit fails on den-55 for RUSTSEC-2026-0538 (quinn-udp 0.5.14, receive loop can spin after a truncated datagram) and RUSTSEC-2026-0592 (url 2.5.8, stack overflow in Url::origin() on nested blob: URLs). The audit workflow only runs on PRs that touch Cargo.toml/Cargo.lock, so the existing den-55 lockfile had not been re-audited since these advisories were published. Lockfile-only patch bumps: quinn-udp 0.5.14 -> 0.5.16, url 2.5.8 -> 2.5.9 (with form_urlencoded 1.2.2 -> 1.2.3). quinn-udp 0.5.16 no longer pulls windows-sys 0.60, so its unused Windows target crates drop out.
aman-ddog
approved these changes
Nov 24, 2026
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?
Backports apache/datafusion#27536 to
den-55(upstreammainonly; not in a release yet).Rationale for this change
When struct arguments differ only in child nullability or metadata, coercion kept each argument's own child fields, so one call could see two different struct types:
Tuples built from table columns hit the same panic because their children carry different
PARQUET:field_idmetadata.What changes are included in this PR?
make_arrayuses it.coerced_fields_metadata, copied verbatim from apache/datafusion#24865 because fix: reconcile Struct fields during type coercion apache/datafusion#27536 calls it. Nothing else uses it yet, so COALESCE/NVL2/CASE metadata behavior is unchanged.HashMapmetadata instead of arrow 60'sMetadata; no behavior change. Only fix: reconcile Struct fields during type coercion apache/datafusion#27536's own tests are included.quinn-udp0.5.14 → 0.5.16 andurl2.5.8 → 2.5.9 to clear RUSTSEC-2026-0538 / RUSTSEC-2026-0592, whichcargo auditflags on the existingden-55lockfile.Are these changes tested?
Yes:
core/tests/sql/select.rs, themake_arrayunit test, andcoalesce.slt. Also the ported helper's unit tests and the related sqllogictests (struct, array, case, nvl, map, union).mem/distributed/clickhousepass, with no panics.Are there any user-facing changes?
Queries that mix tuples differing only in NULL fields or child metadata (array literals,
make_array,coalesce) now return results instead of panicking or failing to plan. Conflicting child extension types now fail at planning time.array_append,array_prepend,array_resize, andarray_hasuse a different coercion path and are not fixed here (upstream either).