@Test public void testSchemaSanitization() throws Exception { Schema avroSchema = SchemaBuilder.builder().unionOf().nullType().and().stringType().and().intType().endUnion(); Schema expectedSchema = SchemaBuilder.builder().unionOf().stringType().and().intType().endUnion(); Assert.assertEquals(sanitizeNullableSchema(avroSchema), expectedSchema); Schema avroSchema_1 = SchemaBuilder.builder() .unionOf() .nullType() .and() .record("test") .fields() .name("aaa") .type(SchemaBuilder.builder().intType()) .noDefault() .endRecord() .endUnion(); expectedSchema = SchemaBuilder.builder() .record("test") .fields() .name("aaa") .type(SchemaBuilder.builder().intType()) .noDefault() .endRecord(); Assert.assertEquals(sanitizeNullableSchema(avroSchema_1), expectedSchema); }
public static Schema sanitizeNullableSchema(Schema avroSchema) { if (avroSchema.getType() != Schema.Type.UNION) { return avroSchema; } List<Schema> members = getNonNullMembersOfUnion(avroSchema); if (isNullableUnion(avroSchema, members)) { return members.get(0); } else { return Schema.createUnion(members); } }
AvroOrcSchemaConverter { public static Schema sanitizeNullableSchema(Schema avroSchema) { if (avroSchema.getType() != Schema.Type.UNION) { return avroSchema; } List<Schema> members = getNonNullMembersOfUnion(avroSchema); if (isNullableUnion(avroSchema, members)) { return members.get(0); } else { return Schema.createUnion(members); } } }
AvroOrcSchemaConverter { public static Schema sanitizeNullableSchema(Schema avroSchema) { if (avroSchema.getType() != Schema.Type.UNION) { return avroSchema; } List<Schema> members = getNonNullMembersOfUnion(avroSchema); if (isNullableUnion(avroSchema, members)) { return members.get(0); } else { return Schema.createUnion(members); } }  }
AvroOrcSchemaConverter { public static Schema sanitizeNullableSchema(Schema avroSchema) { if (avroSchema.getType() != Schema.Type.UNION) { return avroSchema; } List<Schema> members = getNonNullMembersOfUnion(avroSchema); if (isNullableUnion(avroSchema, members)) { return members.get(0); } else { return Schema.createUnion(members); } }  static TypeDescription getOrcSchema(Schema avroSchema); static List<Schema> getNonNullMembersOfUnion(Schema unionSchema); static Schema sanitizeNullableSchema(Schema avroSchema); }
AvroOrcSchemaConverter { public static Schema sanitizeNullableSchema(Schema avroSchema) { if (avroSchema.getType() != Schema.Type.UNION) { return avroSchema; } List<Schema> members = getNonNullMembersOfUnion(avroSchema); if (isNullableUnion(avroSchema, members)) { return members.get(0); } else { return Schema.createUnion(members); } }  static TypeDescription getOrcSchema(Schema avroSchema); static List<Schema> getNonNullMembersOfUnion(Schema unionSchema); static Schema sanitizeNullableSchema(Schema avroSchema);  }