rdblue commented on code in PR #7399:
URL: https://github.com/apache/iceberg/pull/7399#discussion_r1177135907


##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/data/SparkParquetWriters.java:
##########
@@ -316,6 +323,35 @@ public void write(int repetitionLevel, Decimal decimal) {
     }
   }
 
+  private static PrimitiveWriter<UTF8String> uuids(ColumnDescriptor desc) {
+    return new UUIDWriter(desc);
+  }
+
+  private static class UUIDWriter extends PrimitiveWriter<UTF8String> {
+    private static final ThreadLocal<ByteBuffer> BUFFER =
+        ThreadLocal.withInitial(
+            () -> {
+              ByteBuffer buffer = ByteBuffer.allocate(16);
+              buffer.order(ByteOrder.BIG_ENDIAN);
+              return buffer;
+            });
+
+    private UUIDWriter(ColumnDescriptor desc) {
+      super(desc);
+    }
+
+    @Override
+    public void write(int repetitionLevel, UTF8String string) {
+      UUID uuid = UUID.fromString(string.toString());
+      ByteBuffer buffer = BUFFER.get();
+      buffer.rewind();
+      buffer.putLong(uuid.getMostSignificantBits());
+      buffer.putLong(uuid.getLeastSignificantBits());

Review Comment:
   In other places, like `UUIDUtil`, we use `putLong(int offset, long value)` 
instead of `putLong(long value)` so that the position is not updated and we 
don't need to worry about the buffer's internal state. I think that's usually a 
better approach.
   
   Also, we might want to update `UUIDUtil` to share this code:
   
   ```java
     public static ByteBuffer convertToByteBuffer(UUID value) {
       return convertToByteBuffer(value, null);
     }
   
     public static ByteBuffer convertToByteBuffer(UUID value, ByteBuffer reuse) 
{
       ByteBuffer buffer;
       if (reuse != null) {
         buffer = reuse;
       } else {
         buffer = ByteBuffer.allocate(16);
       }
   
       buffer.order(ByteOrder.BIG_ENDIAN);
       buffer.putLong(0, value.getMostSignificantBits());
       buffer.putLong(8, value.getLeastSignificantBits());
       return buffer;
     }
   ```



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