Search in sources :

Example 1 with Builder

use of org.apache.crunch.test.Person.Builder 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)

Aggregations

FileOutputStream (java.io.FileOutputStream)1 DataFileWriter (org.apache.avro.file.DataFileWriter)1 SpecificDatumWriter (org.apache.avro.specific.SpecificDatumWriter)1 Person (org.apache.crunch.test.Person)1 Builder (org.apache.crunch.test.Person.Builder)1