Repository navigation
fix: preserve schema consistency across union and cast - #26200
Closed
Amogh-2404 wants to merge 1 commit into
Closed
Amogh-2404 wants to merge 1 commit into
Amogh-2404 wants to merge 1 commit into
Conversation
Amogh-2404
force-pushed
the
fix/union-cast-field-metadata
branch
from
October 11, 2026 08:20
0d394d2 to
ced67e8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26200 +/- ##
==========================================
- Coverage 82.80% 82.80% -0.01%
==========================================
Files 1149 1149
Lines 452205 452296 +91
Branches 452205 452296 +91
==========================================
+ Hits 374468 374540 +72
- Misses 54942 54944 +2
- Partials 22795 22812 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
CAST(coalesce(non_null_col, lit) AS T)underUNION ALL+ aggregate fails planning when the column carries Arrow field metadata (PARQUET:field_id):coalesceon aNOT NULLcolumn simplifies to the column. Child projections then advertise that metadata; the Union's stored schema still has{}from the pre-simplify coalesce field. Physical planning derives from the simplified exprs, so the aggregate schema check fails.What changes are included in this PR?
LogicalPlan::recompute_schemaforUnionno longer keeps the old schema whenever field count is unchanged. It re-derives viaUnion::try_newso metadata/nullability track the current children. If width is unchanged buttry_newfails (loose-typed children before coercion), the previous schema is kept; width mismatches still return thetry_newerror.What is the testing strategy for this PR?
datafusion/core/tests/sql/union_field_metadata.rs— issue query (m=3,c=6), controls (no metadata /CAST(b)/ directb AS x/ no union), mixed-metadata legs.recompute_schema_refreshes_union_field_metadata, loose-union preserve, width-mismatch error.Verified fail-before / pass-after on
coalesce_cast_union_aggregate_preserves_field_metadataby temporarily reverting theplan.rschange.Commands run:
Not run: full
./dev/rust_lint.sh, full extended CI suite, full sqllogictest corpus.Are there any user-facing changes?
No public API change. Queries that previously hit this internal error now plan. Union output may correctly carry field metadata that a stale schema had dropped after expression rewrites. CAST metadata inheritance is unchanged.