Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Oct 5, 2023
1 parent 61e1d89 commit 5ba9485
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/test/java/org/apache/iceberg/avro/TestReadProjection.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ public void testRename() throws Exception {
Assertions.assertThat(cmp).as("Should contain the correct data/renamed value").isEqualTo(0);
}

@Test
public void testReadOptionalAsRequired() throws Exception {
Schema writeSchema =
new Schema(
Types.NestedField.required(0, "id", Types.LongType.get()),
Types.NestedField.optional(1, "data", Types.StringType.get()));

Record record = new Record(AvroSchemaUtil.convert(writeSchema, "table"));
record.put("id", 34L);
record.put("data", "test");

Schema readSchema =
new Schema(
Types.NestedField.required(0, "id", Types.LongType.get()),
Types.NestedField.required(1, "data", Types.StringType.get()));

Record projected = writeAndRead("read_optional_as_required", writeSchema, readSchema, record);

int cmp = Comparators.charSequences().compare("test", (CharSequence) projected.get("data"));
Assertions.assertThat(cmp).as("Should contain the correct data/renamed value").isEqualTo(0);
}

@Test
public void testNestedStructProjection() throws Exception {
Schema writeSchema =
Expand Down

0 comments on commit 5ba9485

Please sign in to comment.