use of org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat in project presto by prestodb.
the class ParquetRecordWriterUtil method createParquetWriter.
public static RecordWriter createParquetWriter(Path target, JobConf conf, Properties properties, boolean compress, ConnectorSession session) throws IOException, ReflectiveOperationException {
conf.setLong(ParquetOutputFormat.BLOCK_SIZE, getParquetWriterBlockSize(session).toBytes());
conf.setLong(ParquetOutputFormat.PAGE_SIZE, getParquetWriterPageSize(session).toBytes());
RecordWriter recordWriter = new MapredParquetOutputFormat().getHiveRecordWriter(conf, target, Text.class, compress, properties, Reporter.NULL);
Object realWriter = REAL_WRITER_FIELD.get(recordWriter);
Object internalWriter = INTERNAL_WRITER_FIELD.get(realWriter);
ParquetFileWriter fileWriter = (ParquetFileWriter) FILE_WRITER_FIELD.get(internalWriter);
return new ExtendedRecordWriter() {
private long length;
@Override
public long getWrittenBytes() {
return length;
}
@Override
public void write(Writable value) throws IOException {
recordWriter.write(value);
length = fileWriter.getPos();
}
@Override
public void close(boolean abort) throws IOException {
recordWriter.close(abort);
if (!abort) {
length = target.getFileSystem(conf).getFileStatus(target).getLen();
}
}
};
}
use of org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat in project presto by prestodb.
the class ParquetTester method writeParquetColumn.
private static DataSize writeParquetColumn(JobConf jobConf, File outputFile, CompressionCodecName compressionCodecName, ObjectInspector columnObjectInspector, Iterator<?> values) throws Exception {
RecordWriter recordWriter = new MapredParquetOutputFormat().getHiveRecordWriter(jobConf, new Path(outputFile.toURI()), Text.class, compressionCodecName != UNCOMPRESSED, createTableProperties("test", columnObjectInspector.getTypeName()), () -> {
});
SettableStructObjectInspector objectInspector = createSettableStructObjectInspector("test", columnObjectInspector);
Object row = objectInspector.create();
List<StructField> fields = ImmutableList.copyOf(objectInspector.getAllStructFieldRefs());
int i = 0;
while (values.hasNext()) {
Object value = values.next();
objectInspector.setStructFieldData(row, fields.get(0), value);
ParquetHiveSerDe serde = new ParquetHiveSerDe();
serde.initialize(jobConf, createTableProperties("test", columnObjectInspector.getTypeName()), null);
Writable record = serde.serialize(row, objectInspector);
recordWriter.write(record);
i++;
}
recordWriter.close(false);
return succinctBytes(outputFile.length());
}
Aggregations