joyhaldar commented on code in PR #16638:
URL: https://github.com/apache/iceberg/pull/16638#discussion_r3353230771
##########
data/src/test/java/org/apache/iceberg/data/BaseFormatModelTests.java:
##########
@@ -696,49 +733,390 @@ void testReaderBuilderReuseContainers(FileFormat
fileFormat) throws IOException
}
@ParameterizedTest
- @FieldSource("FILE_FORMATS")
- void testReaderSchemaEvolutionNewColumnWithDefault(FileFormat fileFormat)
throws IOException {
+ @FieldSource("FORMAT_AND_PRIMITIVE_DEFAULTS")
+ void testReaderSchemaEvolutionNewColumnWithDefault(
+ FileFormat fileFormat, Type.PrimitiveType type, Literal<?> defaultValue)
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")
+ Types.NestedField.optional("col_with_default")
.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))
+ .ofType(type)
+ .withInitialDefault(defaultValue)
.build());
Schema evolvedSchema = new Schema(evolvedColumns);
- readAndAssertGenericRecords(
+ readAndAssertGenericRecords(fileFormat, evolvedSchema, genericRecords);
+ }
+
+ @ParameterizedTest
+ @FieldSource("FILE_FORMATS")
+ void testDefaultValues(FileFormat fileFormat) throws IOException {
Review Comment:
`testSchemaEvolutionAddColumn` adds plain optional columns that read back as
`null`. `testDefaultValues` instead checks that columns with defaults get the
default injected, and that a written value isn't overwritten by its default,
and there's some overlap there with the new `testPrimitiveDefaultValues`.
@pvary @Guosmilesmile do you think `testDefaultValues` is worth keeping, or
should I remove it?
--
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]