aokolnychyi commented on a change in pull request #135: Use big-endian byte 
order for UUIDs in Conversions
URL: https://github.com/apache/incubator-iceberg/pull/135#discussion_r267127649
 
 

 ##########
 File path: api/src/main/java/com/netflix/iceberg/types/Conversions.java
 ##########
 @@ -98,7 +99,7 @@ public static ByteBuffer toByteBuffer(Type type, Object 
value) {
         }
       case UUID:
         UUID uuid = (UUID) value;
-        return ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN)
+        return ByteBuffer.allocate(16).order(ByteOrder.BIG_ENDIAN)
 
 Review comment:
   @rdblue I am afraid the order is correct but indices are not.
   
   Here is an example I tested:
   
   ```
   UUID randomUUID = UUID.randomUUID();
   System.out.println(randomUUID.toString());
   // abcc5e8d-81f3-4ea2-b624-a14ce8c513b9
   ByteBuffer buffer = Conversions.toByteBuffer(UUIDType.get(), randomUUID);
   Object value = Conversions.fromByteBuffer(UUIDType.get(), buffer);
   System.out.println(value);
   // abb624a1-4ce8-c513-b900-000000000000
   ```
   
   So the logic in `toByteBuffer` should really be:
   
   ```
         case UUID:
           UUID uuid = (UUID) value;
           return ByteBuffer.allocate(16).order(ByteOrder.BIG_ENDIAN)
               .putLong(0, uuid.getMostSignificantBits())
               .putLong(8, uuid.getLeastSignificantBits());
   ```
   
   The test that I added passes because UUIDs are represented as `fixed[16]` in 
Parquet and we invoke only `fromByteBuffer` in this case.
   
   Do we want to have a separate suite for `Conversions`?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to