You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "manner (via GitHub)" <gi...@apache.org> on 2026/09/11 14:36:58 UTC
[PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
manner opened a new pull request, #29163:
URL: https://github.com/apache/flink/pull/29163
## 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](https://cwiki.apache.org/confluence/spaces/FLINK/pages/446070993/FLIP-604+Complete+VARIANT+Primitive+Coverage+with+UUID+and+Timestamps).
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 `VARIANT` → `UUID` case (success and a `TableRuntimeException` for a non-UUID kind) and a `VARIANT` → `STRING` case asserting the canonical rendering.
- `LogicalTypeCastsTest`: `VARIANT` → `UUID` is explicit-only castable; `UUID` → `VARIANT` stays unsupported.
- `CastRuleProviderTest`: the `VARIANT` → `UUID` 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?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 4.8)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r4006251356
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/UuidCastUtils.java:
##########
@@ -46,6 +47,18 @@ public static String toStringValue(byte[] uuidBytes) {
return new UUID(buffer.getLong(), buffer.getLong()).toString();
}
+ /**
+ * 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) {
Review Comment:
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?
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/functions/casting/CastRulesTest.java:
##########
@@ -2034,6 +2040,13 @@ Stream<CastTestSpecBuilder> testCases() {
// them, which is what makes this the way to inspect such a value
.fromCase(VARIANT(), VARIANT_BUILDER.of(INVALID_UTF8), INVALID_UTF8)
.fail(VARIANT(), VARIANT_BUILDER.of("foo"), TableRuntimeException.class),
+ CastTestSpecBuilder.testCastTo(UUID())
+ .fromCase(VARIANT(), null, null)
+ .fromCase(
+ VARIANT(),
+ Variant.newBuilder().of(UUID.fromString(UUID_STRING)),
Review Comment:
Nit: extract UUID.fromString as static field and re-use
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin merged PR #29163:
URL: https://github.com/apache/flink/pull/29163
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r3990552031
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/VariantCastUtils.java:
##########
@@ -271,6 +274,21 @@ public static int toTime(Variant variant, int precision) {
throw unsupportedKind(variant, String.format("TIME(%d)", precision));
}
+ /**
+ * Reads a UUID variant as the target {@code UUID}, encoded as the canonical 16-byte big-endian
+ * representation.
+ */
+ public static byte[] toUuid(Variant variant) {
+ if (variant.getType() == Variant.Type.UUID) {
+ final UUID uuid = variant.getUuid();
+ final ByteBuffer buffer = ByteBuffer.allocate(UuidType.BYTE_LENGTH);
+ buffer.putLong(uuid.getMostSignificantBits());
Review Comment:
nit: maybe worth adding buffer.order(ByteOrder.BIG_ENDIAN); so it is explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #29163:
URL: https://github.com/apache/flink/pull/29163#issuecomment-5636245864
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "71f6cb8cfafa3b11561e9f133eb354c4cef6dced",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "71f6cb8cfafa3b11561e9f133eb354c4cef6dced",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 71f6cb8cfafa3b11561e9f133eb354c4cef6dced UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "manner (via GitHub)" <gi...@apache.org>.
manner commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r3990708139
##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeCastsTest.java:
##########
@@ -386,11 +387,11 @@ private static Stream<Arguments> testData() {
Arguments.of(new BinaryType(10), new UuidType(), false, false),
// UUID identity cast is implicit
Arguments.of(new UuidType(), new UuidType(), true, true),
- // numeric and VARIANT are not castable to or from UUID
+ // numeric is not castable to or from UUID
Arguments.of(new UuidType(), new IntType(), false, false),
Arguments.of(new IntType(), new UuidType(), false, false),
- 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));
Review Comment:
There's an identity cast test in line 389: `Arguments.of(new UuidType(), new UuidType(), true, true)`. Did you mean that one?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r4004881506
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/VariantCastUtils.java:
##########
@@ -271,6 +275,22 @@ public static int toTime(Variant variant, int precision) {
throw unsupportedKind(variant, String.format("TIME(%d)", precision));
}
+ /**
+ * Reads a UUID variant as the target {@code UUID}, encoded as the canonical 16-byte big-endian
+ * representation.
+ */
+ public static byte[] toUuid(Variant variant) {
Review Comment:
or even may be have same name, just different arg
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r3990499752
##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeCastsTest.java:
##########
@@ -386,11 +387,11 @@ private static Stream<Arguments> testData() {
Arguments.of(new BinaryType(10), new UuidType(), false, false),
// UUID identity cast is implicit
Arguments.of(new UuidType(), new UuidType(), true, true),
- // numeric and VARIANT are not castable to or from UUID
+ // numeric is not castable to or from UUID
Arguments.of(new UuidType(), new IntType(), false, false),
Arguments.of(new IntType(), new UuidType(), false, false),
- 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));
Review Comment:
I assume casting to its existing type is safe - does it warrant a test?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r4004873999
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/VariantCastUtils.java:
##########
@@ -271,6 +275,22 @@ public static int toTime(Variant variant, int precision) {
throw unsupportedKind(variant, String.format("TIME(%d)", precision));
}
+ /**
+ * Reads a UUID variant as the target {@code UUID}, encoded as the canonical 16-byte big-endian
+ * representation.
+ */
+ public static byte[] toUuid(Variant variant) {
Review Comment:
I wonder if it would be better to move it to `UuidCastUtils` where we already have `toUuidBytes`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r4006217953
##########
flink-table/flink-table-common/src/test/java/org/apache/flink/table/types/LogicalTypeCastsTest.java:
##########
@@ -386,11 +387,11 @@ private static Stream<Arguments> testData() {
Arguments.of(new BinaryType(10), new UuidType(), false, false),
// UUID identity cast is implicit
Arguments.of(new UuidType(), new UuidType(), true, true),
- // numeric and VARIANT are not castable to or from UUID
+ // numeric is not castable to or from UUID
Arguments.of(new UuidType(), new IntType(), false, false),
Arguments.of(new IntType(), new UuidType(), false, false),
- 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));
Review Comment:
For now this test is fine. For the future we will add support of CAST primitive dataTypes to Variant.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "manner (via GitHub)" <gi...@apache.org>.
manner commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r4006582923
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/UuidCastUtils.java:
##########
@@ -46,6 +47,18 @@ public static String toStringValue(byte[] uuidBytes) {
return new UUID(buffer.getLong(), buffer.getLong()).toString();
}
+ /**
+ * 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) {
Review Comment:
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`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-40493][table] Support casting from VARIANT to UUID [flink]
Posted by "manner (via GitHub)" <gi...@apache.org>.
manner commented on code in PR #29163:
URL: https://github.com/apache/flink/pull/29163#discussion_r4004983261
##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/VariantCastUtils.java:
##########
@@ -271,6 +275,22 @@ public static int toTime(Variant variant, int precision) {
throw unsupportedKind(variant, String.format("TIME(%d)", precision));
}
+ /**
+ * Reads a UUID variant as the target {@code UUID}, encoded as the canonical 16-byte big-endian
+ * representation.
+ */
+ public static byte[] toUuid(Variant variant) {
Review Comment:
Makes sense, thanks @snuyanzin
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org