rzhang10 commented on code in PR #4525:
URL: https://github.com/apache/iceberg/pull/4525#discussion_r847670673


##########
api/src/main/java/org/apache/iceberg/types/Types.java:
##########
@@ -524,6 +563,91 @@ public boolean equals(Object o) {
     public int hashCode() {
       return Objects.hash(NestedField.class, id, isOptional, name, type);
     }
+
+    private static JsonNode validateDefault(String name, Type type, JsonNode 
defaultValue) {
+      if (defaultValue != null && !isValidDefault(type, defaultValue)) {
+        throw new ValidationException("Invalid default value for field %s: %s 
not a %s", name, defaultValue, type);
+      }
+      return defaultValue;
+    }
+
+    @SuppressWarnings("checkstyle:CyclomaticComplexity")
+    private static boolean isValidDefault(Type type, JsonNode defaultValue) {

Review Comment:
   I feel using a `SchemaVisitor` here would be an overkill, since this logic 
is only validating a `NestField`, it's technically only part of the schema, and 
even if it's a complex type, we only recursively validate downward, but not 
upward. Also I feel readability-wise, this recursive implementation is clean 
enough? it clearly shows the logic is to validate each type of default value 
case-by-case.
   
   To me, I feel `SchemaVisitor` is mostly used to do holistic schema 
manipulations/transformations.



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