Guosmilesmile commented on code in PR #15843:
URL: https://github.com/apache/iceberg/pull/15843#discussion_r3132080793
##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -609,6 +640,315 @@ void
testReaderBuilderRecordsPerBatchNotSupported(FileFormat fileFormat) throws
.isInstanceOf(UnsupportedOperationException.class);
}
+ /**
+ * Schema evolution: Adding column (reading with wider schema). Write with
DefaultSchema, read
+ * with additional optional columns. The new columns should be filled with
null values.
+ */
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testSchemaEvolutionAddColumn(FileFormat fileFormat) throws IOException {
+ DataGenerator dataGenerator = new DataGenerators.DefaultSchema();
+ Schema writeSchema = dataGenerator.schema();
+
+ List<Record> genericRecords = dataGenerator.generateRecords();
+ writeGenericRecords(fileFormat, writeSchema, genericRecords);
+
+ List<Types.NestedField> evolvedColumns =
Lists.newArrayList(writeSchema.columns());
+
+ int maxFieldId =
+
writeSchema.columns().stream().mapToInt(Types.NestedField::fieldId).max().orElse(0);
+ evolvedColumns.add(
+ Types.NestedField.optional("new_string_col")
+ .withId(maxFieldId + 1)
+ .ofType(Types.StringType.get())
+ .build());
+ evolvedColumns.add(
+ Types.NestedField.optional("new_int_col")
+ .withId(maxFieldId + 2)
+ .ofType(Types.IntegerType.get())
+ .build());
+ Schema readSchema = new Schema(evolvedColumns);
+ readAndAssertEngineRecords(
+ fileFormat,
+ readSchema,
+ genericRecords,
+ record -> {
+ Record expected = GenericRecord.create(readSchema);
+ for (Types.NestedField col : writeSchema.columns()) {
+ expected.setField(col.name(), record.getField(col.name()));
+ }
+
+ expected.setField("new_string_col", null);
+ expected.setField("new_int_col", null);
+ return expected;
Review Comment:
Good suggestion, make it simple.
--
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]