Package org.apache.crunch.test

Examples of org.apache.crunch.test.Person


  }

  @Test
  public void testMemPipelineWithSpecificRecord() {

    Person writeRecord = createSpecificRecord();

    final PCollection<Person> writeCollection = MemPipeline.typedCollectionOf(
                                                  Avros.specifics(Person.class),
                                                  writeRecord);

    writeCollection.write(To.avroFile(avroFile.getAbsolutePath()));

    PCollection<Person> readCollection = MemPipeline.getInstance().read(
        At.avroFile(avroFile.getAbsolutePath(), Avros.records(Person.class)));

    Person readRecord = readCollection.materialize().iterator().next();

    assertEquals(writeRecord, readRecord);
  }
View Full Code Here


  }
 
  @Test
  public void testDeepCopy_Null() {
    Person person = null;

    Person deepCopyPerson = new AvroSpecificDeepCopier<Person>(Person.class, Person.SCHEMA$)
        .deepCopy(person);

    assertNull(deepCopyPerson);
  }
View Full Code Here

    assertEquals(writeRecord, readRecord);
  }

  private Person createSpecificRecord() {
    List<CharSequence> siblingnames = Lists.newArrayList();
    return new Person("John", 41, siblingnames);
  }
View Full Code Here

    File outputFile = tmpDir.getFile("output");
    Target trevniFile = new TrevniKeyTarget(outputFile.getAbsolutePath());
    pipeline.write(genericCollection, trevniFile);
    pipeline.run();

    Person person = genericCollection.materialize().iterator().next();

    File trvFile = new File(outputFile, "part-m-00000-part-0.trv");

    AvroColumnReader.Params params = new AvroColumnReader.Params(trvFile);
    params.setSchema(Person.SCHEMA$);
    params.setModel(SpecificData.get());
    AvroColumnReader<Person> reader = new AvroColumnReader<Person>(params);

    try{
      Person readPerson = reader.next();
      assertThat(readPerson, is(person));
    }finally{
      reader.close();
    }
  }
View Full Code Here

    File output2File = tmpDir.getFile("output2");
    pipeline.write(genericCollection, new TrevniKeyTarget(output1File.getAbsolutePath()));
    pipeline.write(genericCollection, new TrevniKeyTarget(output2File.getAbsolutePath()));
    pipeline.run();

    Person person = genericCollection.materialize().iterator().next();

    File trv1File = new File(output1File, "part-m-00000-part-0.trv");
    File trv2File = new File(output2File, "part-m-00000-part-0.trv");

    AvroColumnReader.Params params = new AvroColumnReader.Params(trv1File);
    params.setSchema(Person.SCHEMA$);
    params.setModel(SpecificData.get());
    AvroColumnReader<Person> reader = new AvroColumnReader<Person>(params);

    try{
      Person readPerson = reader.next();
      assertThat(readPerson, is(person));
    }finally{
      reader.close();
    }

    params = new AvroColumnReader.Params(trv2File);
    params.setSchema(Person.SCHEMA$);
    params.setModel(SpecificData.get());
    reader = new AvroColumnReader<Person>(params);

    try{
      Person readPerson = reader.next();
      assertThat(readPerson, is(person));
    }finally{
      reader.close();
    }
  }
View Full Code Here

    File outputFile = tmpDir.getFile("output");
    Target trevniFile = new TrevniKeyTarget(outputFile.getAbsolutePath());
    pipeline.write(genericCollection, trevniFile);
    pipeline.run();

    Person person = genericCollection.materialize().iterator().next();

    PCollection<Person> retrievedPeople = pipeline.read(new TrevniKeySource<Person>(
        new Path(outputFile.toURI()), Avros.records(Person.class)));

    Person retrievedPerson = retrievedPeople.materialize().iterator().next();

    assertThat(retrievedPerson, is(person));

    File trvFile = new File(outputFile, "part-m-00000-part-0.trv");

    AvroColumnReader.Params params = new AvroColumnReader.Params(trvFile);
    params.setSchema(Person.SCHEMA$);
    params.setModel(SpecificData.get());
    AvroColumnReader<Person> reader = new AvroColumnReader<Person>(params);

    try{
      Person readPerson = reader.next();
      assertThat(readPerson, is(person));
    }finally{
      reader.close();
    }
  }
View Full Code Here

public class TupleDeepCopierTest {

  @Test
  public void testDeepCopy_Pair() {
    Person person = new Person();
    person.name = "John Doe";
    person.age = 42;
    person.siblingnames = Lists.<CharSequence> newArrayList();

    Pair<Integer, Person> inputPair = Pair.of(1, person);
View Full Code Here

    pipeline.done();
  }

  private static void createPersonAvroFile(File avroFile) throws IOException {

    Person person = new Person();
    person.age = 40;
    person.name = "Bob";
    List<CharSequence> siblingNames = Lists.newArrayList();
    siblingNames.add("Bob1");
    siblingNames.add("Bob2");
View Full Code Here

  public static class MapReducePersonMapper extends
      Mapper<LongWritable, Text, AvroKey<Person>, AvroValue<Integer>> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
      Person person = Person.newBuilder()
          .setName(value.toString())
          .setAge(value.toString().length())
          .setSiblingnames(ImmutableList.<CharSequence>of())
          .build();
      context.write(
View Full Code Here

  }

  public static class MapRedPersonMapper implements org.apache.hadoop.mapred.Mapper<LongWritable, Text, AvroWrapper<Pair<Person,Integer>>, NullWritable> {
    @Override
    public void map(LongWritable key, Text value, OutputCollector<AvroWrapper<Pair<Person,Integer>>, NullWritable> outputCollector, Reporter reporter) throws IOException {
      Person person = Person.newBuilder()
          .setName(value.toString())
          .setAge(value.toString().length())
          .setSiblingnames(ImmutableList.<CharSequence>of())
          .build();
      outputCollector.collect(
View Full Code Here

TOP

Related Classes of org.apache.crunch.test.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.