Skip to content

fix: plan TRY_CAST struct casts by field name like CAST - #27647

Open
ahlag wants to merge 1 commit into
apache:mainfrom
ahlag:try-cast-struct-by-name
Open

ahlag wants to merge 1 commit into
apache:mainfrom
ahlag:try-cast-struct-by-name

Conversation

@ahlag

@ahlag ahlag commented Nov 22, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Closes #26528.

Rationale for this change

TRY_CAST rejects struct casts at planning time that CAST accepts, such as when the target has an additional nullable field.

What changes are included in this PR?

  • Extracted the existing by-name struct check into a shared can_plan_cast helper used by both CAST and TRY_CAST.
  • Runtime behavior is unchanged, as both already cast struct fields by name in ColumnarValue::cast_to.
  • Replaces the closed fix: plan TRY_CAST struct casts by field name like CAST #26529 with a smaller change and improved regression tests.

What is the testing strategy for this PR?

Added regression cases to struct.slt covering missing fields, failed casts returning NULL, lists of structs, and structs with no matching field names still failing at planning time.

The positive cases fail on main and pass with this fix.

Are there any user-facing changes?

TRY_CAST now accepts additional valid struct casts. No public API changes.

Remaining questions

This also moves CAST's two inline checks into the shared helper to prevent the paths from drifting apart. Happy to limit the change to TRY_CAST if preferred.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TRY_CAST rejects valid struct casts at planning time

1 participant