huaxingao commented on code in PR #14700:
URL: https://github.com/apache/iceberg/pull/14700#discussion_r2578846346
##########
api/src/main/java/org/apache/iceberg/util/UUIDUtil.java:
##########
@@ -78,4 +81,29 @@ public static ByteBuffer convertToByteBuffer(UUID value,
ByteBuffer reuse) {
buffer.putLong(8, value.getLeastSignificantBits());
return buffer;
}
+
+ /**
+ * Generate a RFC 9562 UUIDv7 string.
+ *
+ * <p>Layout: - 48-bit Unix epoch milliseconds - 4-bit version (0b0111) -
12-bit random (rand_a) -
+ * 2-bit variant (RFC 4122, 0b10) - 62-bit random (rand_b)
+ */
+ public static String generateUuidV7() {
+ long epochMs = System.currentTimeMillis();
+ if ((epochMs >>> 48) != 0) {
+ throw new IllegalArgumentException("timestamp does not fit within 48
bits: " + epochMs);
+ }
+
+ long randA = SECURE_RANDOM.nextLong() & 0xFFFL; // 12 bits
Review Comment:
Switched to a single SecureRandom.nextBytes. Thanks for the suggestion!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]