Guosmilesmile commented on code in PR #15843:
URL: https://github.com/apache/iceberg/pull/15843#discussion_r3142725293
##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -1330,6 +1357,288 @@ private void readAndAssertGenericRecords(
readAndAssertGenericRecords(fileFormat, schema,
sourceRecords.stream().map(transform).toList());
}
+ /**
+ * 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 = copy(record, writeSchema, readSchema);
+
+ expected.setField("new_string_col", null);
+ expected.setField("new_int_col", null);
+ return expected;
+ });
+ }
+
+ /**
+ * Schema evolution: Projection / Removing column (reading with narrower
schema). Write with
+ * DefaultSchema, read with only a subset of columns (skipping middle
columns).
+ */
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testSchemaEvolutionProjection(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> writeColumns = writeSchema.columns();
+ assumeThat(writeColumns).hasSizeGreaterThanOrEqualTo(2);
+ Schema projectedSchema =
+ new Schema(writeColumns.get(0), writeColumns.get(writeColumns.size() -
1));
+
+ readAndAssertEngineRecords(
+ fileFormat,
+ projectedSchema,
+ genericRecords,
+ record -> copy(record, projectedSchema, projectedSchema));
+ }
+
+ /**
+ * Schema evolution: Removing and adding a column with the same name (name
mapping). Write with
Review Comment:
My bed, Clearn it now.
--
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]