}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void writeAvroFile(FSDataOutputStream outputStream, PCollection recordCollection) throws IOException {
AvroType avroType = (AvroType)recordCollection.getPType();
if (avroType == null) {
throw new IllegalStateException("Can't write a non-typed Avro collection");
}
DatumWriter datumWriter = Avros.newWriter((AvroType)recordCollection.getPType());
DataFileWriter dataFileWriter = new DataFileWriter(datumWriter);
dataFileWriter.create(avroType.getSchema(), outputStream);
for (Object record : recordCollection.materialize()) {
dataFileWriter.append(avroType.getOutputMapFn().map(record));
}
dataFileWriter.close();
outputStream.close();
}