use of org.apache.crunch.impl.mr.MRPipeline in project crunch by cloudera.
the class AvroFileSourceTargetTest method testGeneric.
@Test
public void testGeneric() throws IOException {
String genericSchemaJson = Person.SCHEMA$.toString().replace("Person", "GenericPerson");
Schema genericPersonSchema = new Schema.Parser().parse(genericSchemaJson);
GenericRecord savedRecord = new GenericData.Record(genericPersonSchema);
savedRecord.put("name", "John Doe");
savedRecord.put("age", 42);
savedRecord.put("siblingnames", Lists.newArrayList("Jimmy", "Jane"));
populateGenericFile(Lists.newArrayList(savedRecord), genericPersonSchema);
Pipeline pipeline = new MRPipeline(AvroFileSourceTargetTest.class);
PCollection<Record> genericCollection = pipeline.read(At.avroFile(avroFile.getAbsolutePath(), Avros.generics(genericPersonSchema)));
List<Record> recordList = Lists.newArrayList(genericCollection.materialize());
assertEquals(Lists.newArrayList(savedRecord), Lists.newArrayList(recordList));
}
use of org.apache.crunch.impl.mr.MRPipeline in project crunch by cloudera.
the class AvroReflectTest method testReflection.
@Test
public void testReflection() throws IOException {
Pipeline pipeline = new MRPipeline(AvroReflectTest.class);
PCollection<StringWrapper> stringWrapperCollection = pipeline.readTextFile(FileHelper.createTempCopyOf("set1.txt")).parallelDo(new MapFn<String, StringWrapper>() {
@Override
public StringWrapper map(String input) {
StringWrapper stringWrapper = new StringWrapper();
stringWrapper.setValue(input);
return stringWrapper;
}
}, Avros.reflects(StringWrapper.class));
List<StringWrapper> stringWrappers = Lists.newArrayList(stringWrapperCollection.materialize());
pipeline.done();
assertEquals(Lists.newArrayList(new StringWrapper("b"), new StringWrapper("c"), new StringWrapper("a"), new StringWrapper("e")), stringWrappers);
}
use of org.apache.crunch.impl.mr.MRPipeline in project crunch by cloudera.
the class PageRankTest method testAvroJSON.
@Test
public void testAvroJSON() throws Exception {
PTypeFamily tf = AvroTypeFamily.getInstance();
PType<PageRankData> prType = PTypes.jsonString(PageRankData.class, tf);
run(new MRPipeline(PageRankTest.class), prType, tf);
}
use of org.apache.crunch.impl.mr.MRPipeline in project crunch by cloudera.
the class PageRankTest method testAvroReflect.
@Test
public void testAvroReflect() throws Exception {
PTypeFamily tf = AvroTypeFamily.getInstance();
PType<PageRankData> prType = Avros.reflects(PageRankData.class);
run(new MRPipeline(PageRankTest.class), prType, tf);
}
use of org.apache.crunch.impl.mr.MRPipeline in project crunch by cloudera.
the class PageRankTest method testAvroBSON.
@Test
public void testAvroBSON() throws Exception {
PTypeFamily tf = AvroTypeFamily.getInstance();
PType<PageRankData> prType = PTypes.smile(PageRankData.class, tf);
run(new MRPipeline(PageRankTest.class), prType, tf);
}
Aggregations