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/04 12:55:48 UTC

[PR] [FLINK-40515][core] Extend BinaryVariant to support UUID [flink]

manner opened a new pull request, #29103:
URL: https://github.com/apache/flink/pull/29103

   ## What is the purpose of the change
   
   Adds UUID (primitive type code 20) as a supported VARIANT primitive in `BinaryVariant`. 
   
   The 16-byte layout follows the open variant spec, which stores UUID big-endian. UUID is the only variant primitive that is not little-endian, so it uses dedicated big-endian read/write helpers. 
   ## Brief change log
   
     - Add the UUID primitive (code 20) to `BinaryVariantUtil`: type mapping in `getType`, a `case UUID` in `valueSize`, and the `getUUID` reader
     - Add big-endian long helpers `writeLongBigEndian` / `readLongBigEndian`; a UUID is stored as its two 64-bit halves in 16 big-endian bytes
     - Add `appendUUID` to `BinaryVariantInternalBuilder` and `of(UUID)` to `BinaryVariantBuilder`
     - Add `getUUID()` and `Type.UUID` to the `Variant` interface and `of(UUID)` to `VariantBuilder`, and wire UUID into `get()` and `toJson()`
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
     - Added scalar round-trip and `toJson` assertions for UUID variants
     - Added `testUuidDecodeFromSpecBytes`, which decodes the exact byte sequence from Iceberg's `TestSerializedPrimitives#testUUID` to confirm the wire format is compatible across implementations of the spec
    
   ## 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)`: **yes** (`Variant` and `VariantBuilder` are `@PublicEvolving`, this adds new enum constants and new interface methods)
     - 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? **not documented** (documentation is tracked separately in [FLINK-40494](https://issues.apache.org/jira/browse/FLINK-40494))
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude 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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "manner (via GitHub)" <gi...@apache.org>.
manner commented on PR #29103:
URL: https://github.com/apache/flink/pull/29103#issuecomment-5572358419

   @flinkbot run azure


-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3940078714


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);

Review Comment:
   > value.length should be the size of the whole variant data
   
   Answers my question!



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "twalthr (via GitHub)" <gi...@apache.org>.
twalthr commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3950851443


##########
flink-core/src/main/java/org/apache/flink/types/variant/Variant.java:
##########
@@ -171,6 +172,14 @@ public interface Variant extends Serializable {
      */
     byte[] getBytes() throws VariantTypeException;
 
+    /**
+     * Get the scalar value of variant as UUID, if the variant type is {@link Type#UUID}.
+     *
+     * @throws VariantTypeException If this variant is not a scalar value or is not {@link
+     *     Type#UUID}.
+     */
+    UUID getUUID() throws VariantTypeException;

Review Comment:
   ```suggestion
       UUID getUuid() throws VariantTypeException;
   ```



##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantBuilder.java:
##########
@@ -168,6 +169,13 @@ public Variant of(LocalTime localTime) {
         return builder.build();
     }
 
+    @Override
+    public Variant of(UUID uuid) {
+        BinaryVariantInternalBuilder builder = new BinaryVariantInternalBuilder(false);
+        builder.appendUUID(uuid);

Review Comment:
   ```suggestion
           builder.appendUuid(uuid);
   ```
   
   > The Modern/Google Style: appendUuid
   Modern style guides—most notably the Google Java Style Guide—mandate that acronyms should be treated as regular words. Under this rule, "UUID" becomes "Uuid", making your method appendUuid.



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3941316162


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);
+        int basicType = value[pos] & BASIC_TYPE_MASK;
+        int typeInfo = (value[pos] >> BASIC_TYPE_BITS) & TYPE_INFO_MASK;
+        if (basicType != PRIMITIVE || typeInfo != UUID) {
+            throw unexpectedType(Type.UUID);
+        }
+        // The 16 UUID bytes are big-endian (most significant bytes first): the most significant 8
+        // bytes followed by the least significant 8 bytes.
+        long msb = readLongBigEndian(value, pos + 1);
+        long lsb = readLongBigEndian(value, pos + 9);

Review Comment:
   do we need to have check for length/position 3 times within this method?
   Can we do it only once?



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3934377163


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);

Review Comment:
   Should we do a early check of `value.length == 16` or is it always guarantied?



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3941316162


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);
+        int basicType = value[pos] & BASIC_TYPE_MASK;
+        int typeInfo = (value[pos] >> BASIC_TYPE_BITS) & TYPE_INFO_MASK;
+        if (basicType != PRIMITIVE || typeInfo != UUID) {
+            throw unexpectedType(Type.UUID);
+        }
+        // The 16 UUID bytes are big-endian (most significant bytes first): the most significant 8
+        // bytes followed by the least significant 8 bytes.
+        long msb = readLongBigEndian(value, pos + 1);
+        long lsb = readLongBigEndian(value, pos + 9);

Review Comment:
   do we need to have check for length/position 3-5 times within this method?
   Can we do it only once?



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3941321112


##########
flink-core/src/test/java/org/apache/flink/types/variant/BinaryVariantTest.java:
##########
@@ -105,6 +106,10 @@ void testScalarVariant() {
         assertThat(builder.of(localTime).getTime()).isEqualTo(localTime);
         assertThat(builder.of(localTime).get()).isEqualTo(localTime);
 
+        UUID uuid = UUID.randomUUID();

Review Comment:
   we don't have negative tests, do we?
   can we have some of them?



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #29103:
URL: https://github.com/apache/flink/pull/29103#issuecomment-5540813217

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "b216a66f37dbebb78bd2cab6c6c283657ba19c6a",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "b216a66f37dbebb78bd2cab6c6c283657ba19c6a",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * b216a66f37dbebb78bd2cab6c6c283657ba19c6a 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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "raminqaf (via GitHub)" <gi...@apache.org>.
raminqaf commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3940095666


##########
flink-core/src/test/java/org/apache/flink/types/variant/BinaryVariantTest.java:
##########
@@ -105,6 +106,10 @@ void testScalarVariant() {
         assertThat(builder.of(localTime).getTime()).isEqualTo(localTime);
         assertThat(builder.of(localTime).get()).isEqualTo(localTime);
 
+        UUID uuid = UUID.randomUUID();
+        assertThat(builder.of(uuid).getUUID()).isEqualTo(uuid);
+        assertThat(builder.of(uuid).get()).isEqualTo(uuid);

Review Comment:
   Do we have any test that evaluates broken values? Like an invalid UUID?



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "manner (via GitHub)" <gi...@apache.org>.
manner commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3947655218


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);
+        int basicType = value[pos] & BASIC_TYPE_MASK;
+        int typeInfo = (value[pos] >> BASIC_TYPE_BITS) & TYPE_INFO_MASK;
+        if (basicType != PRIMITIVE || typeInfo != UUID) {
+            throw unexpectedType(Type.UUID);
+        }
+        // The 16 UUID bytes are big-endian (most significant bytes first): the most significant 8
+        // bytes followed by the least significant 8 bytes.
+        long msb = readLongBigEndian(value, pos + 1);
+        long lsb = readLongBigEndian(value, pos + 9);

Review Comment:
   I was following the style of the other helper methods that each helper check its bounds before accessing the `byte[]`. I can remove the checks from `readLongBigEndian()`, because it's currently only used in the `getUUID` method, but then any future caller would also need to do the checks manually. 



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "manner (via GitHub)" <gi...@apache.org>.
manner commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3934548782


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);

Review Comment:
   Mhm, `value.length` should be the size of the whole variant data, not just the UUID, so I don't think we can compare to that size. And the bounds are checked inside `readLongBigEndian()` again if the `byte[]` is too short. Maybe you can clarify which check you mean.



-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin merged PR #29103:
URL: https://github.com/apache/flink/pull/29103


-- 
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-40515][core] Extend BinaryVariant to support UUID [flink]

Posted by "snuyanzin (via GitHub)" <gi...@apache.org>.
snuyanzin commented on code in PR #29103:
URL: https://github.com/apache/flink/pull/29103#discussion_r3941316162


##########
flink-core/src/main/java/org/apache/flink/types/variant/BinaryVariantUtil.java:
##########
@@ -674,6 +703,20 @@ public static String getString(byte[] value, int pos) {
         throw unexpectedType(Type.STRING);
     }
 
+    public static UUID getUUID(byte[] value, int pos) {
+        checkIndex(pos, value.length);
+        int basicType = value[pos] & BASIC_TYPE_MASK;
+        int typeInfo = (value[pos] >> BASIC_TYPE_BITS) & TYPE_INFO_MASK;
+        if (basicType != PRIMITIVE || typeInfo != UUID) {
+            throw unexpectedType(Type.UUID);
+        }
+        // The 16 UUID bytes are big-endian (most significant bytes first): the most significant 8
+        // bytes followed by the least significant 8 bytes.
+        long msb = readLongBigEndian(value, pos + 1);
+        long lsb = readLongBigEndian(value, pos + 9);

Review Comment:
   do we need to have check for length 3 times within this method?
   Can we do it only once?



-- 
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