RussellSpitzer commented on code in PR #15977:
URL: https://github.com/apache/iceberg/pull/15977#discussion_r3175270953


##########
api/src/main/java/org/apache/iceberg/types/Types.java:
##########
@@ -878,22 +878,25 @@ private NestedField(
       this.name = name;
       this.type = type;
       this.doc = doc;
-      this.initialDefault = castDefault(initialDefault, type);
-      this.writeDefault = castDefault(writeDefault, type);
+      this.initialDefault = initDefault(isOptional, initialDefault, type);
+      this.writeDefault = initDefault(isOptional, writeDefault, type);
     }
 
-    private static Literal<?> castDefault(Literal<?> defaultValue, Type type) {
-      if (type.isNestedType() && defaultValue != null) {
+    private static Literal<?> initDefault(boolean isOptional, Literal<?> 
defaultValue, Type type) {
+      if (defaultValue == null) {
+        return null;
+      } else if (defaultValue.equals(Literal.ofNull())) {
+        Preconditions.checkArgument(isOptional, "Cannot use null default for 
required field");

Review Comment:
   Let's see if we can give a bit more information here to the user. 
   "Cannot use null default for required field %s"
   ```suggestion
               Preconditions.checkArgument(isOptional, "Cannot use null default 
for required field: %s (%s)", name, type);
   ```



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