Skip to content

[FLINK-40672][table] Preserve nullability when casting VARIANT values - #29202

Open
dylanhz wants to merge 1 commit into
apache:masterfrom
dylanhz:FLINK-40672
Open

dylanhz wants to merge 1 commit into
apache:masterfrom
dylanhz:FLINK-40672

Conversation

@dylanhz

@dylanhz dylanhz commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fix FLINK-40672: CAST(PARSE_JSON('null') AS INT) should return SQL NULL. A non-null VARIANT can contain JSON null, but deriving CAST nullability solely from the source type can produce a non-null result type and cause the cast to fail.

Brief change log

  • Apply Calcite's VARIANT nullability rules to Flink's SQL CAST type derivation.
  • Make Table API casts from VARIANT to other types nullable and use the inferred result type in planner conversion. Preserve VARIANT-to-VARIANT and nested target nullability.
  • Extend the existing type strategy and CAST integration tests.

Verifying this change

  • TypeStrategiesTest: 34 tests passed.
  • CastFunctionITCase: 951 tests passed using JUnit and MiniCluster, including SQL, Table API, and Table API-to-SQL serialization.
  • Spotless and Checkstyle passed for flink-table-common and flink-table-planner.

The full repository clean verify suite was not run.

Does this pull request potentially affect one of the following parts:

  • Dependencies: no.
  • The public API: yes; corrects the inferred nullability of CAST results. No API signatures change.
  • The serializers: no.
  • The runtime per-record code paths: yes; corrected nullability enables the existing VARIANT-null handling in generated CAST code.
  • Deployment or recovery: no.
  • The S3 file system connector: no.

Documentation

  • Does this pull request introduce a new feature? No.
  • If yes, how is the feature documented? Not applicable.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Codex (GPT-6)

@flinkbot

flinkbot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@twalthr

twalthr commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Thank you for catching this @dylanhz. @raminqaf is out of office this week, but will take a look after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants