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;
}
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();
}
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);
}
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));
}
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);
}
Aggregations