Repository navigation
fix: preserve schema consistency across union and cast - #26201
Open
Amogh-2404 wants to merge 1 commit into
Open
Amogh-2404 wants to merge 1 commit into
Amogh-2404 wants to merge 1 commit into
Conversation
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.