kbendick commented on a change in pull request #4037:
URL: https://github.com/apache/iceberg/pull/4037#discussion_r799075359



##########
File path: core/src/main/java/org/apache/iceberg/util/JsonUtil.java
##########
@@ -117,6 +127,31 @@ public static String getStringOrNull(String property, 
JsonNode node) {
     return builder.build();
   }
 
+  public static Map<String, String> getStringMapOrNull(String property, 
JsonNode node) {
+    if (!node.has(property)) {
+      return null;
+    }
+
+    JsonNode pNode = node.get(property);
+    if (pNode == null || pNode.isNull()) {
+      return null;
+    }
+
+    Preconditions.checkArgument(pNode.isObject(),
+        "Cannot parse %s from non-object value: %s", property, pNode);
+    return buildStringMapFromJsonNodeObject(pNode);
+  }
+
+  private static Map<String, String> buildStringMapFromJsonNodeObject(JsonNode 
pNode) {
+    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+    Iterator<String> fields = pNode.fieldNames();
+    while (fields.hasNext()) {
+      String field = fields.next();
+      builder.put(field, getString(field, pNode));
+    }
+    return builder.build();

Review comment:
       This function is written such that it can be used in `getStringMap` and 
the differences between `getStringMap` and `getStringMapOrNull` would be in 
precondition checks, but I chose not to make that change to the existing code 
for now.




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