chenhao-db commented on code in PR #50025:
URL: https://github.com/apache/spark/pull/50025#discussion_r1970383080


##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantUtil.java:
##########
@@ -497,6 +508,19 @@ public static String getString(byte[] value, int pos) {
     throw unexpectedType(Type.STRING);
   }
 
+  // Get a UUID value from variant value `value[pos...]`.
+  // Throw `MALFORMED_VARIANT` if the variant is malformed.
+  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);
+    int start = pos + 1;
+    // UUID values are big-endian, so we can't use VariantUtil.readLong().
+    ByteBuffer bb = ByteBuffer.wrap(value, start, 
16).order(ByteOrder.BIG_ENDIAN);

Review Comment:
   Should we check `value` has enough bytes before this line? We may want to 
throw a malformed variant exception instead of some Java out-of-bound exception.



##########
common/variant/src/main/java/org/apache/spark/types/variant/VariantShreddingWriter.java:
##########
@@ -283,6 +283,11 @@ private static Object tryTypedShred(
           return v.getBinary();
         }
         break;
+      case UUID:
+        if (targetType instanceof VariantSchema.UuidType) {

Review Comment:
   This is unreachable if called from Spark, right?



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

Reply via email to