Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aihuaxu committed Feb 20, 2025
1 parent 7bf7db7 commit 7f39dae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static boolean isKeyValueSchema(Schema schema) {
return schema.getType() == RECORD && schema.getFields().size() == 2;
}

public static boolean isVariantSchema(Schema schema) {
static boolean isVariantSchema(Schema schema) {
return schema.getType() == RECORD
&& schema.getFields().size() == 2
&& schema.getField("metadata") != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,22 @@ public void testFieldDocsArePreserved() {
Lists.newArrayList(Iterables.transform(origSchema.columns(), Types.NestedField::doc));
assertThat(fieldDocs).isEqualTo(origFieldDocs);
}

@Test
public void testVariantConversion() {
org.apache.iceberg.Schema schema =
new org.apache.iceberg.Schema(
required(1, "variantCol1", Types.VariantType.get()),
required(2, "variantCol2", Types.VariantType.get()));
org.apache.avro.Schema avroSchema = AvroSchemaUtil.convert(schema.asStruct());

for (int id : Lists.newArrayList(1, 2)) {
org.apache.avro.Schema variantSchema = avroSchema.getField("variantCol" + id).schema();
assertThat(variantSchema.getType()).isEqualTo(org.apache.avro.Schema.Type.RECORD);
assertThat(variantSchema.getFields().size()).isEqualTo(2);
assertThat(variantSchema.getField("metadata").schema().getType())
.isEqualTo(Schema.Type.BYTES);
assertThat(variantSchema.getField("value").schema().getType()).isEqualTo(Schema.Type.BYTES);
}
}
}

0 comments on commit 7f39dae

Please sign in to comment.