[FLINK-37926][table] Support casting from VARIANT to ROW and STRUCTURED - #29092
Merged
Merged
Conversation
Collaborator
raminqaf
force-pushed
the
FLINK-37926-variant-to-row
branch
from
September 4, 2026 12:49
ae81af5 to
80922ee
Compare
raminqaf
marked this pull request as ready for review
September 4, 2026 12:49
twalthr
reviewed
Sep 4, 2026
raminqaf
force-pushed
the
FLINK-37926-variant-to-row
branch
2 times, most recently
from
September 6, 2026 11:13
d2ff425 to
7219b16
Compare
1 task
raminqaf
force-pushed
the
FLINK-37926-variant-to-row
branch
from
September 7, 2026 06:40
7219b16 to
bfc1d22
Compare
twalthr
approved these changes
Sep 7, 2026
raminqaf
added a commit
to raminqaf/flink
that referenced
this pull request
Sep 7, 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.
What is the purpose of the change
This pull request adds
CASTandTRY_CASTfromVARIANTto the constructed typesROWandSTRUCTURED, so a variant object can be given a schema. It is stacked on #29073 (VARIANT toARRAY), reuses the same design, and should be reviewed and merged after it.A constructed cast is the scalar leaf cast applied to every field plus a shape check at each level. The recursion bottoms out at the same scalar casts the primitive and string rules perform, so no new leaf semantics are introduced.
Key semantics:
ROWdeclared without field names uses the default namesf0,f1, and so on, which must then be present in the object.NULLwhen the field is nullable and fails the cast when it isNOT NULL.VARIANTtarget field takes the identity cast and keeps a variant null as a variant null rather than turning it into SQLNULL. This matchesARRAY<VARIANT>and the top level VARIANT cast.STRUCTUREDshares theRowDatarepresentation and is served by the same rule.TRY_CASTreturnsNULLfor the entire value.Brief change log
VariantToRowCastRulethat casts a variant object toROWorSTRUCTURED, matching fields by name and casting each field with the existing VARIANT to leaf rules.LogicalTypeCastswhenVARIANTcasts to every target field type.ROWandSTRUCTUREDcast in the data types reference.Verifying this change
This change added tests and can be verified as follows:
CastRulesTest: by-name matching, free field order, absent field, present variant null in nullable andNOT NULLfields, projection of extra fields, nested rows and arrays, an unnamedROW,ROW<VARIANT>with and without a variant null, and aSTRUCTUREDtarget.CastFunctionITCase: end to end SQL and Table API cases, includingROW<VARIANT>round trips back to a concrete row.LogicalTypeCastsTestandCastRuleProviderTest: castability and rule resolution.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Opus 4.8