rdblue commented on code in PR #6004:
URL: https://github.com/apache/iceberg/pull/6004#discussion_r1002769125


##########
core/src/main/java/org/apache/iceberg/avro/BuildAvroProjection.java:
##########
@@ -102,9 +102,17 @@ public Schema record(Schema record, List<String> names, 
Iterable<Schema.Field> s
 
       } else {
         Preconditions.checkArgument(
-            field.isOptional() || 
MetadataColumns.metadataFieldIds().contains(field.fieldId()),
-            "Missing required field: %s",
+            (field.isRequired() && field.initialDefault() != null)
+                || field.isOptional()
+                || 
MetadataColumns.metadataFieldIds().contains(field.fieldId()),
+            "Missing required field that doesn't have a default value: %s",
             field.name());
+        // If the field from Iceberg schema has initial default value, we just 
pass and don't
+        // project it to the avro file read schema with the generated _r field 
name,
+        // the default value will be directly read from the Iceberg layer
+        if (field.initialDefault() != null) {

Review Comment:
   Why does the case for a `null` default add a field while this one does not? 
That seems strange to me. I think this should either add a fake field in both 
cases or not.
   
   I think the question hinges on why the fake field is added for the other 
case. I think it has something to do with the record schema needing to match 
the Iceberg schema exactly -- the record schema should not be different. If 
that's the case then it should be added for the non-null initial default.



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