Raghu Bommineni
01/15/2024, 10:30 PMAshwin Bharadwaj
01/16/2024, 8:04 AMAshwin Bharadwaj
01/16/2024, 8:04 AMRaghu Bommineni
01/16/2024, 5:03 PMpublic class ParquetAvroWriterFactoryT extends GenericRecord implements BulkWriter.FactoryT {
private final Schema schema;
private final CompressionCodecName codecName;
private final Path path;
public ParquetAvroWriterFactory(Schema schema, CompressionCodecName codecName, Path path) {
this.schema = schema;
this.codecName = codecName;
this.path = path;
}
@Override
public BulkWriterT create(org.apache.flink.core.fs.FSDataOutputStream out) throws IOException {
// Convert Flink output stream to Hadoop output file
Path path = new Path("hdfs://hdfsserver:8020/path_to_folder");
OutputFile outputFile = HadoopOutputFile.fromPath(path, new Configuration());
// Create a ParquetWriter
ParquetWriterT writer = AvroParquetWriter.Tbuilder(outputFile)
.withSchema(schema)
.withCompressionCodec(codecName)
.build();
return new BulkWriterT() {
@Override
public void addElement(T element) throws IOException {
writer.write(element);
}
@Override
public void flush() throws IOException {
// ParquetWriter handles its own flushing, so this can be left empty
}
@Override
public void finish() throws IOException {
writer.close();
}
};
}
}
the schema I'm using is json in .avsc file that I generated using ReflectData like this
Schema schema = ReflectData.get().getSchema(ClassBeingConvertedToParquet.class);