shardulm94 commented on a change in pull request #2496:
URL: https://github.com/apache/iceberg/pull/2496#discussion_r616294869



##########
File path: api/src/main/java/org/apache/iceberg/types/Types.java
##########
@@ -415,42 +415,74 @@ public int hashCode() {
 
   public static class NestedField implements Serializable {
     public static NestedField optional(int id, String name, Type type) {
-      return new NestedField(true, id, name, type, null);
+      return new NestedField(true, id, name, type, null, null);
     }
 
     public static NestedField optional(int id, String name, Type type, String 
doc) {
-      return new NestedField(true, id, name, type, doc);
+      return new NestedField(true, id, name, type, null, doc);
+    }
+
+    public static NestedField optional(int id, String name, Type type, Object 
defaultValue, String doc) {
+      return new NestedField(true, id, name, type, defaultValue, doc);
+    }
+
+    public static NestedField optionalWithDefault(int id, String name, Type 
type, Object defaultValue) {
+      return new NestedField(true, id, name, type, defaultValue, null);
     }
 
     public static NestedField required(int id, String name, Type type) {
-      return new NestedField(false, id, name, type, null);
+      return new NestedField(false, id, name, type, null, null);
     }
 
     public static NestedField required(int id, String name, Type type, String 
doc) {
-      return new NestedField(false, id, name, type, doc);
+      return new NestedField(false, id, name, type, null, doc);
+    }
+
+    public static NestedField required(int id, String name, Type type, Object 
defaultValue, String doc) {
+      validateDefaultValueForRequiredField(defaultValue);
+      return new NestedField(false, id, name, type, defaultValue, doc);
+    }
+
+    public static NestedField requiredWithDefault(int id, String name, Type 
type, Object defaultValue) {
+      validateDefaultValueForRequiredField(defaultValue);
+      return new NestedField(false, id, name, type, defaultValue, null);
     }
 
     public static NestedField of(int id, boolean isOptional, String name, Type 
type) {
-      return new NestedField(isOptional, id, name, type, null);
+      return new NestedField(isOptional, id, name, type, null, null);
     }
 
     public static NestedField of(int id, boolean isOptional, String name, Type 
type, String doc) {
-      return new NestedField(isOptional, id, name, type, doc);
+      return new NestedField(isOptional, id, name, type, null, doc);
+    }
+
+    public static NestedField of(int id, boolean isOptional, String name, Type 
type, Object defaultValue, String doc) {
+      return new NestedField(isOptional, id, name, type, defaultValue, doc);
+    }
+
+    private static void validateDefaultValueForRequiredField(Object 
defaultValue) {
+      Preconditions.checkNotNull(defaultValue, "defaultValue cannot be null 
for a required field");
     }
 
     private final boolean isOptional;
     private final int id;
     private final String name;
     private final Type type;
+    private final Object defaultValue;
     private final String doc;
 
-    private NestedField(boolean isOptional, int id, String name, Type type, 
String doc) {
+    private NestedField(boolean isOptional, int id, String name, Type type, 
Object defaultValue, String doc) {
       Preconditions.checkNotNull(name, "Name cannot be null");
       Preconditions.checkNotNull(type, "Type cannot be null");
+      if (defaultValue != null) {
+        Preconditions.checkArgument(defaultValue.getClass() == 
type.typeId().javaClass(),

Review comment:
       Do we support default values for fields with container types like 
`struct`, `list`, `map`? Today `Type#javaClass` will return `Void` for such 
types. 
https://github.com/apache/iceberg/blob/6c6096d44cd1315c40e1e718c3186ba8927c3219/api/src/main/java/org/apache/iceberg/types/Type.java#L43-L45
 What class should the user provide?
   
   We may need to think about the implications of changing those to a non-void 
class. The class `Comparators` has a private method 
[`internalClass`](https://github.com/apache/iceberg/blob/6c6096d44cd1315c40e1e718c3186ba8927c3219/api/src/main/java/org/apache/iceberg/types/Comparators.java#L88)
 handled the java classes for container types. Perhaps we could also do 
something similar.




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

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