seokyun-ha-toss commented on code in PR #15283:
URL: https://github.com/apache/iceberg/pull/15283#discussion_r3055382231


##########
kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:
##########
@@ -464,6 +479,218 @@ protected Temporal convertTimestampValue(Object value, 
TimestampType type) {
     return convertLocalDateTime(value);
   }
 
+  protected Variant convertVariantValue(Object value) {
+    if (value instanceof ByteBuffer) {
+      return Variant.from((ByteBuffer) value);
+    }
+
+    Set<String> fieldNames = Sets.newHashSet();
+    collectFieldNames(value, fieldNames);
+    List<String> allFieldNames = 
fieldNames.stream().sorted().collect(Collectors.toList());
+    VariantMetadata metadata = Variants.metadata(allFieldNames);
+    VariantValue variantValue = objectToVariantValue(value, metadata, null);
+    return Variant.of(metadata, variantValue);
+  }
+
+  /**
+   * Collects all field names (map keys) from the entire object tree into the 
given set. Used to
+   * build a single VariantMetadata for the whole Variant (required for nested 
maps).
+   */
+  private static void collectFieldNames(Object value, Set<String> names) {
+    if (value == null) {
+      return;
+    }
+    if (value instanceof Collection) {
+      for (Object element : (Collection<?>) value) {
+        collectFieldNames(element, names);
+      }
+      return;
+    }
+    if (value instanceof Map) {
+      Map<?, ?> map = (Map<?, ?>) value;
+      for (Map.Entry<?, ?> entry : map.entrySet()) {
+        Object key = entry.getKey();
+        if (key != null && key instanceof String) {
+          names.add((String) key);
+          collectFieldNames(entry.getValue(), names);
+        }

Review Comment:
   great! I added `throw` in else block! 
https://github.com/apache/iceberg/pull/15283/commits/818a5155e075b9c008dc86a26fef9caffb6c0981
 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