use of org.apache.beam.sdk.io.AvroGeneratedUser in project beam by apache.
the class AvroUtilsTest method testAvroSchemaCoders.
@Test
public void testAvroSchemaCoders() {
Pipeline pipeline = Pipeline.create();
org.apache.avro.Schema schema = org.apache.avro.Schema.createRecord("TestSubRecord", "TestSubRecord doc", "org.apache.beam.sdk.schemas.utils", false, getAvroSubSchemaFields());
GenericRecord record = new GenericRecordBuilder(getAvroSubSchema("simple")).set("bool", true).set("int", 42).build();
PCollection<GenericRecord> records = pipeline.apply(Create.of(record).withCoder(AvroCoder.of(schema)));
assertFalse(records.hasSchema());
records.setCoder(AvroUtils.schemaCoder(schema));
assertTrue(records.hasSchema());
CoderProperties.coderSerializable(records.getCoder());
AvroGeneratedUser user = new AvroGeneratedUser("foo", 42, "green");
PCollection<AvroGeneratedUser> users = pipeline.apply(Create.of(user).withCoder(AvroCoder.of(AvroGeneratedUser.class)));
assertFalse(users.hasSchema());
users.setCoder(AvroUtils.schemaCoder((AvroCoder<AvroGeneratedUser>) users.getCoder()));
assertTrue(users.hasSchema());
CoderProperties.coderSerializable(users.getCoder());
}
Aggregations