pvary commented on code in PR #15675:
URL: https://github.com/apache/iceberg/pull/15675#discussion_r3099915840


##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -609,6 +622,57 @@ void testReaderBuilderReuseContainers(FileFormat 
fileFormat) throws IOException
     reuseRecords.forEach(r -> assertThat(r).isSameAs(reuseRecords.get(0)));
   }
 
+  @ParameterizedTest
+  @FieldSource("FILE_FORMATS")
+  void testReaderSchemaEvolutionNewColumnWithDefault(FileFormat fileFormat) 
throws IOException {
+
+    assumeSupports(fileFormat, FEATURE_READER_DEFAULT);
+    DataGenerator dataGenerator = new DataGenerators.DefaultSchema();
+    Schema writeSchema = dataGenerator.schema();
+
+    List<Record> genericRecords = dataGenerator.generateRecords();
+    writeGenericRecords(fileFormat, writeSchema, genericRecords);
+
+    String defaultStringValue = "default_value";
+    int defaultIntValue = 42;
+
+    int maxFieldId =
+        
writeSchema.columns().stream().mapToInt(Types.NestedField::fieldId).max().orElse(0);
+
+    List<Types.NestedField> evolvedColumns = 
Lists.newArrayList(writeSchema.columns());
+    evolvedColumns.add(
+        Types.NestedField.required("col_f")
+            .withId(maxFieldId + 1)
+            .ofType(Types.StringType.get())
+            .withInitialDefault(Literal.of(defaultStringValue))
+            .build());
+    evolvedColumns.add(
+        Types.NestedField.optional("col_g")
+            .withId(maxFieldId + 2)
+            .ofType(Types.IntegerType.get())
+            .withInitialDefault(Literal.of(defaultIntValue))
+            .build());
+
+    Schema evolvedSchema = new Schema(evolvedColumns);
+
+    List<Record> expectedGenericRecords =
+        genericRecords.stream()
+            .map(
+                record -> {
+                  Record expected = GenericRecord.create(evolvedSchema);
+                  for (Types.NestedField col : writeSchema.columns()) {
+                    expected.setField(col.name(), record.getField(col.name()));
+                  }
+
+                  expected.setField("col_f", defaultStringValue);
+                  expected.setField("col_g", defaultIntValue);
+                  return expected;
+                })
+            .toList();
+
+    readAndAssertGenericRecords(fileFormat, evolvedSchema, 
expectedGenericRecords);

Review Comment:
   You are right, we need to pass the `genericRecords` too.
   The diff is not that significant here, but it is more pronounced where the 
conversion is simpler



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