@Test
public void testProjection() throws IOException {
String genericSchemaJson = Person.SCHEMA$.toString().replace("Person", "GenericPerson");
Schema genericPersonSchema = new Schema.Parser().parse(genericSchemaJson);
GenericRecord savedRecord = new Record(genericPersonSchema);
savedRecord.put("name", "John Doe");
savedRecord.put("age", 42);
savedRecord.put("siblingnames", Lists.newArrayList("Jimmy", "Jane"));
populateGenericFile(Lists.newArrayList(savedRecord), genericPersonSchema);
Schema projection = Schema.createRecord("projection", null, null, false);
projection.setFields(Lists.newArrayList(cloneField(genericPersonSchema.getField("name"))));
AvroParquetFileReaderFactory<Record> genericReader = createFileReaderFactory(Avros.generics(projection));
Iterator<Record> recordIterator = genericReader.read(FileSystem.getLocal(new Configuration()),
new Path(this.parquetFile.getAbsolutePath()));
GenericRecord genericRecord = recordIterator.next();
assertEquals(savedRecord.get("name"), genericRecord.get("name"));
assertNull(genericRecord.get("age"));
assertFalse(recordIterator.hasNext());
}