Search in sources :

Example 1 with Person

use of org.apache.crunch.test.Person in project crunch by cloudera.

the class AvroTypeSortTest method createPerson.

private Person createPerson(String name, int age) throws IOException {
    Person person = new Person();
    person.setAge(age);
    person.setName(name);
    List<CharSequence> siblingNames = Lists.newArrayList();
    person.setSiblingnames(siblingNames);
    return person;
}
Also used : Person(org.apache.crunch.test.Person)

Example 2 with Person

use of org.apache.crunch.test.Person in project crunch by cloudera.

the class SpecificAvroGroupByTest method createPersonAvroFile.

private void createPersonAvroFile(File avroFile) throws IOException {
    Builder person = Person.newBuilder();
    person.setAge(40);
    person.setName("Bob");
    List<CharSequence> siblingNames = Lists.newArrayList();
    siblingNames.add("Bob" + "1");
    siblingNames.add("Bob" + "2");
    person.setSiblingnames(siblingNames);
    FileOutputStream outputStream = new FileOutputStream(avroFile);
    SpecificDatumWriter<Person> writer = new SpecificDatumWriter<Person>(Person.class);
    DataFileWriter<Person> dataFileWriter = new DataFileWriter<Person>(writer);
    dataFileWriter.create(Person.SCHEMA$, outputStream);
    dataFileWriter.append(person.build());
    dataFileWriter.close();
    outputStream.close();
}
Also used : Builder(org.apache.crunch.test.Person.Builder) FileOutputStream(java.io.FileOutputStream) DataFileWriter(org.apache.avro.file.DataFileWriter) Person(org.apache.crunch.test.Person) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter)

Example 3 with Person

use of org.apache.crunch.test.Person in project crunch by cloudera.

the class AvroDeepCopierTest method testDeepCopySpecific.

@Test
public void testDeepCopySpecific() {
    Person person = new Person();
    person.setName("John Doe");
    person.setAge(42);
    person.setSiblingnames(Lists.<CharSequence>newArrayList());
    Person deepCopyPerson = new AvroSpecificDeepCopier<Person>(Person.class, Person.SCHEMA$).deepCopy(person);
    assertEquals(person, deepCopyPerson);
    assertNotSame(person, deepCopyPerson);
}
Also used : Person(org.apache.crunch.test.Person) Test(org.junit.Test)

Example 4 with Person

use of org.apache.crunch.test.Person in project crunch by cloudera.

the class AvroGroupedTableTypeTest method testGetDetachedValue.

@Test
public void testGetDetachedValue() {
    Integer integerValue = 42;
    Person person = new Person();
    person.setName("John Doe");
    person.setAge(42);
    person.setSiblingnames(Lists.<CharSequence>newArrayList());
    Iterable<Person> inputPersonIterable = Lists.newArrayList(person);
    Pair<Integer, Iterable<Person>> pair = Pair.of(integerValue, inputPersonIterable);
    PGroupedTableType<Integer, Person> groupedTableType = Avros.tableOf(Avros.ints(), Avros.reflects(Person.class)).getGroupedTableType();
    Pair<Integer, Iterable<Person>> detachedPair = groupedTableType.getDetachedValue(pair);
    assertSame(integerValue, detachedPair.first());
    List<Person> personList = Lists.newArrayList(detachedPair.second());
    assertEquals(inputPersonIterable, personList);
    assertNotSame(person, personList.get(0));
}
Also used : Person(org.apache.crunch.test.Person) Test(org.junit.Test)

Example 5 with Person

use of org.apache.crunch.test.Person in project crunch by cloudera.

the class AvroTypeTest method testGetDetachedValue_SpecificAvroType.

@Test
public void testGetDetachedValue_SpecificAvroType() {
    AvroType<Person> specificType = Avros.records(Person.class);
    Person person = new Person();
    person.setName("name value");
    person.setAge(42);
    person.setSiblingnames(Lists.<CharSequence>newArrayList());
    Person detachedPerson = specificType.getDetachedValue(person);
    assertEquals(person, detachedPerson);
    assertNotSame(person, detachedPerson);
}
Also used : Person(org.apache.crunch.test.Person) Test(org.junit.Test)

Aggregations

Person (org.apache.crunch.test.Person)15 Test (org.junit.Test)11 DataFileWriter (org.apache.avro.file.DataFileWriter)3 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)3 MRPipeline (org.apache.crunch.impl.mr.MRPipeline)3 FileOutputStream (java.io.FileOutputStream)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 Pipeline (org.apache.crunch.Pipeline)2 Employee (org.apache.crunch.test.Employee)2 Path (org.apache.hadoop.fs.Path)2 Record (org.apache.avro.generic.GenericData.Record)1 MapFn (org.apache.crunch.MapFn)1 Pair (org.apache.crunch.Pair)1 PojoPerson (org.apache.crunch.io.avro.AvroFileReaderFactoryTest.PojoPerson)1 Builder (org.apache.crunch.test.Person.Builder)1 Configuration (org.apache.hadoop.conf.Configuration)1 Before (org.junit.Before)1