Package org.apache.crunch.test

Examples of org.apache.crunch.test.Person


    assertNotSame(value, detachedMap.get(key));
  }

  @Test
  public void testGetDetachedValue_TupleN() {
    Person person = createPerson();
    AvroType<TupleN> ptype = Avros.tuples(Avros.records(Person.class));
    ptype.initialize(new Configuration());
    TupleN tuple = new TupleN(person);
    TupleN detachedTuple = ptype.getDetachedValue(tuple);
View Full Code Here


@RunWith(AvroChildClassloaderTestRunner.class)
public class AvroSpecificDeepCopierClassloaderTest {

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

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

    assertEquals(person, deepCopyPerson);
    assertNotSame(person, deepCopyPerson);
  }
View Full Code Here

    assertEquals(pair, doubleMappedPair);
  }

  @Test
  public void testPairs_Specific() {
    Person personA = new Person();
    Person personB = new Person();

    personA.age = 1;
    personA.name = "A";
    personA.siblingnames = Collections.<CharSequence> emptyList();
View Full Code Here

  @Test
  public void testSortAvroTypesBySelectedFields() throws Exception {

    MRPipeline pipeline = new MRPipeline(AvroTypeSortIT.class, tmpDir.getDefaultConfiguration());

    Person ccc10 = createPerson("CCC", 10);
    Person bbb20 = createPerson("BBB", 20);
    Person aaa30 = createPerson("AAA", 30);

    writeAvroFile(Lists.newArrayList(ccc10, bbb20, aaa30), avroFile);

    PCollection<Person> unsorted = pipeline.read(At.avroFile(avroFile.getAbsolutePath(), records(Person.class)));
View Full Code Here

    outputStream.close();
  }

  private static Person createPerson(String name, int age) {

    Person person = new Person();
    person.age = age;
    person.name = name;
    person.siblingnames = Lists.newArrayList();

    return person;
View Full Code Here

    PCollection<Person> genericCollection = pipeline.read(new TrevniKeySource(new Path(avroFile.getAbsolutePath()),
        Avros.records(Person.class)));

    List<Person> personList = Lists.newArrayList(genericCollection.materialize());

    Person expectedPerson = new Person();
    expectedPerson.name = "John Doe";
    expectedPerson.age = 42;

    List<CharSequence> siblingNames = Lists.newArrayList();
    siblingNames.add("Jimmy");
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.trv-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.trv-part-0.trv");
    File trv2File = new File(output2File, "part-m-00000.trv-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.trv-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

    PCollection<Pair<StringWrapper, Person>> hybridPairCollection = pipeline.readTextFile(
        tmpDir.copyResourceFileName("set1.txt")).parallelDo(new MapFn<String, Pair<StringWrapper, Person>>() {

      @Override
      public Pair<StringWrapper, Person> map(String input) {
        Person person = new Person();
        person.name = input;
        person.age = 42;
        person.siblingnames = Lists.<CharSequence> newArrayList(input);

        return Pair.of(new StringWrapper(input), person);
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.