Skip to content

[FLINK-40493][table] Support casting from VARIANT to UUID - #29163

Open
manner wants to merge 4 commits into
apache:masterfrom
manner:FLINK-40493
Open

[FLINK-40493][table] Support casting from VARIANT to UUID#29163
manner wants to merge 4 commits into
apache:masterfrom
manner:FLINK-40493

Conversation

@manner

@manner manner commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

This pull request adds CAST and TRY_CAST from a VARIANT holding a UUID (variant primitive code 20) to the native UUID type, completing UUID coverage for VARIANT under FLIP-604.

A VARIANT whose stored kind is UUID can now be cast to the UUID type, and it renders to a character string in the canonical lower-case 8-4-4-4-12 form like any other scalar kind.

Consistent with the existing VARIANT-cast semantics, a cast never reinterprets the stored kind, so the UUID variant casts only to UUID (and to a string).

Brief change log

  • VariantCastUtils.toUuid decodes a UUID-kind variant into the 16-byte big-endian encoding used internally for the UUID type, renderScalar gains a UUID case producing the canonical string.
  • VariantToPrimitiveCastRule accepts UUID as a target and generates the toUuid call.
  • LogicalTypeCasts declares VARIANT as an explicit source for castTo(UUID).
  • Documentation (data-types.md, both content and content.zh) lists UUID in the "stored kind → succeeds for" table for VARIANT casts.

Verifying this change

This change added tests and can be verified as follows:

  • CastRulesTest: added a VARIANTUUID case (success and a TableRuntimeException for a non-UUID kind) and a VARIANTSTRING case asserting the canonical rendering.
  • LogicalTypeCastsTest: VARIANTUUID is explicit-only castable; UUIDVARIANT stays unsupported.
  • CastRuleProviderTest: the VARIANTUUID rule resolves.

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

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? docs

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

Generated-by: Claude Code (Opus 4.8)

@flinkbot

flinkbot commented Sep 11, 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

Arguments.of(new UuidType(), new VariantType(), false, false),
Arguments.of(new VariantType(), new UuidType(), false, false));
// a UUID does not cast to VARIANT
Arguments.of(new UuidType(), new VariantType(), false, false));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume casting to its existing type is safe - does it warrant a test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an identity cast test in line 389: Arguments.of(new UuidType(), new UuidType(), true, true). Did you mean that one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now this test is fine. For the future we will add support of CAST primitive dataTypes to Variant.

@davidradl davidradl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve pending the CI completing and the small comments being addressed.

@raminqaf raminqaf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @manner! I left some nits. Should be good in the next round!

* Encodes a {@code UUID} into the canonical 16-byte big-endian representation used to store a
* {@code UUID} value.
*/
public static byte[] toUuidBytes(UUID uuid) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this piece of code exists in many places for UUID now. Could you double check if we can re-use this method more and replace the duplicates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current location only RexLiteralUtil in the planner can reuse it, to deduplicate it also in UuidUuidConverter it would have to move to flink-table-common.

.fromCase(VARIANT(), null, null)
.fromCase(
VARIANT(),
Variant.newBuilder().of(UUID.fromString(UUID_STRING)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extract UUID.fromString as static field and re-use

@github-actions github-actions Bot added the community-reviewed PR has been reviewed by the community. label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-reviewed PR has been reviewed by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants