Search in sources :

Example 1 with PojoPerson

use of org.apache.crunch.io.avro.AvroFileReaderFactoryTest.PojoPerson in project crunch by cloudera.

the class AvroFileSourceTargetTest method testReflect.

@Test
public void testReflect() throws IOException {
    Schema pojoPersonSchema = ReflectData.get().getSchema(PojoPerson.class);
    GenericRecord savedRecord = new GenericData.Record(pojoPersonSchema);
    savedRecord.put("name", "John Doe");
    populateGenericFile(Lists.newArrayList(savedRecord), pojoPersonSchema);
    Pipeline pipeline = new MRPipeline(AvroFileSourceTargetTest.class);
    PCollection<PojoPerson> personCollection = pipeline.read(At.avroFile(avroFile.getAbsolutePath(), Avros.reflects(PojoPerson.class)));
    List<PojoPerson> recordList = Lists.newArrayList(personCollection.materialize());
    assertEquals(1, recordList.size());
    PojoPerson person = recordList.get(0);
    assertEquals("John Doe", person.getName());
}
Also used : PojoPerson(org.apache.crunch.io.avro.AvroFileReaderFactoryTest.PojoPerson) Schema(org.apache.avro.Schema) MRPipeline(org.apache.crunch.impl.mr.MRPipeline) GenericRecord(org.apache.avro.generic.GenericRecord) Record(org.apache.avro.generic.GenericData.Record) GenericRecord(org.apache.avro.generic.GenericRecord) Pipeline(org.apache.crunch.Pipeline) MRPipeline(org.apache.crunch.impl.mr.MRPipeline) Test(org.junit.Test)

Aggregations

Schema (org.apache.avro.Schema)1 Record (org.apache.avro.generic.GenericData.Record)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 Pipeline (org.apache.crunch.Pipeline)1 MRPipeline (org.apache.crunch.impl.mr.MRPipeline)1 PojoPerson (org.apache.crunch.io.avro.AvroFileReaderFactoryTest.PojoPerson)1 Test (org.junit.Test)1