Skip to content

Commit

Permalink
Sync TestGenericData with Parquet version.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdblue committed Dec 16, 2024
1 parent ebb35b9 commit a9896a4
Showing 1 changed file with 96 additions and 14 deletions.
110 changes: 96 additions & 14 deletions data/src/test/java/org/apache/iceberg/data/avro/TestGenericData.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,11 @@ protected void writeAndValidate(Schema writeSchema, Schema expectedSchema) throw

@Test
public void testMissingRequiredWithoutDefault() {
Schema writeSchema =
new Schema(
required(1, "id", Types.LongType.get()),
Types.NestedField.optional("data")
.withId(2)
.ofType(Types.StringType.get())
.withInitialDefault("wrong!")
.withDoc("Should not produce default value")
.build());
Schema writeSchema = new Schema(required(1, "id", Types.LongType.get()));

Schema expectedSchema =
new Schema(
required(1, "id", Types.LongType.get()),
Types.NestedField.optional("data")
.withId(2)
.ofType(Types.StringType.get())
.withInitialDefault("wrong!")
.build(),
Types.NestedField.required("missing_str")
.withId(6)
.ofType(Types.StringType.get())
Expand Down Expand Up @@ -208,4 +195,99 @@ public void testNestedDefaultValue() throws IOException {

writeAndValidate(writeSchema, expectedSchema);
}

@Test
public void testMapNestedDefaultValue() throws IOException {
Schema writeSchema =
new Schema(
required(1, "id", Types.LongType.get()),
Types.NestedField.optional("data")
.withId(2)
.ofType(Types.StringType.get())
.withInitialDefault("wrong!")
.withDoc("Should not produce default value")
.build(),
Types.NestedField.optional("nested_map")
.withId(3)
.ofType(
Types.MapType.ofOptional(
4,
5,
Types.StringType.get(),
Types.StructType.of(required(6, "value_str", Types.StringType.get()))))
.withDoc("Used to test nested map value field defaults")
.build());

Schema expectedSchema =
new Schema(
required(1, "id", Types.LongType.get()),
Types.NestedField.optional("data")
.withId(2)
.ofType(Types.StringType.get())
.withInitialDefault("wrong!")
.build(),
Types.NestedField.optional("nested_map")
.withId(3)
.ofType(
Types.MapType.ofOptional(
4,
5,
Types.StringType.get(),
Types.StructType.of(
required(6, "value_str", Types.StringType.get()),
Types.NestedField.optional("value_int")
.withId(7)
.ofType(Types.IntegerType.get())
.withInitialDefault(34)
.build())))
.withDoc("Used to test nested field defaults")
.build());

writeAndValidate(writeSchema, expectedSchema);
}

@Test
public void testListNestedDefaultValue() throws IOException {
Schema writeSchema =
new Schema(
required(1, "id", Types.LongType.get()),
Types.NestedField.optional("data")
.withId(2)
.ofType(Types.StringType.get())
.withInitialDefault("wrong!")
.withDoc("Should not produce default value")
.build(),
Types.NestedField.optional("nested_list")
.withId(3)
.ofType(
Types.ListType.ofOptional(
4, Types.StructType.of(required(5, "element_str", Types.StringType.get()))))
.withDoc("Used to test nested field defaults")
.build());

Schema expectedSchema =
new Schema(
required(1, "id", Types.LongType.get()),
Types.NestedField.optional("data")
.withId(2)
.ofType(Types.StringType.get())
.withInitialDefault("wrong!")
.build(),
Types.NestedField.optional("nested_list")
.withId(3)
.ofType(
Types.ListType.ofOptional(
4,
Types.StructType.of(
required(5, "element_str", Types.StringType.get()),
Types.NestedField.optional("element_int")
.withId(7)
.ofType(Types.IntegerType.get())
.withInitialDefault(34)
.build())))
.withDoc("Used to test nested field defaults")
.build());

writeAndValidate(writeSchema, expectedSchema);
}
}

0 comments on commit a9896a4

Please sign in to comment.