huaxingao commented on code in PR #14379:
URL: https://github.com/apache/iceberg/pull/14379#discussion_r2464187981


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/source/StructInternalRow.java:
##########
@@ -229,14 +231,38 @@ public MapData getMap(int ordinal) {
     return isNullAt(ordinal) ? null : getMapInternal(ordinal);
   }
 
+  private MapData getMapInternal(int ordinal) {
+    return mapToMapData(
+        type.fields().get(ordinal).type().asMapType(), struct.get(ordinal, 
Map.class));
+  }
+
   @Override
   public VariantVal getVariant(int ordinal) {
-    throw new UnsupportedOperationException("Unsupported method: getVariant");
+    return isNullAt(ordinal) ? null : getVariantInternal(ordinal);
   }
 
-  private MapData getMapInternal(int ordinal) {
-    return mapToMapData(
-        type.fields().get(ordinal).type().asMapType(), struct.get(ordinal, 
Map.class));
+  private VariantVal getVariantInternal(int ordinal) {
+    Object value = struct.get(ordinal, Object.class);
+
+    if (value instanceof VariantVal) {
+      return (VariantVal) value;
+    }
+
+    if (value instanceof Variant) {
+      Variant variant = (Variant) value;
+      byte[] metadataBytes = new byte[variant.metadata().sizeInBytes()];
+      ByteBuffer metadataBuffer = 
ByteBuffer.wrap(metadataBytes).order(ByteOrder.LITTLE_ENDIAN);
+      variant.metadata().writeTo(metadataBuffer, 0);
+
+      byte[] valueBytes = new byte[variant.value().sizeInBytes()];
+      ByteBuffer valueBuffer = 
ByteBuffer.wrap(valueBytes).order(ByteOrder.LITTLE_ENDIAN);
+      variant.value().writeTo(valueBuffer, 0);
+
+      return new VariantVal(valueBytes, metadataBytes);
+    }
+
+    throw new UnsupportedOperationException(
+        "Unsupported value for VARIANT in StructInternalRow: " + 
value.getClass());
   }
 

Review Comment:
   Added. Thanks



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