Search in sources :

Example 1 with ParquetWriter

use of com.facebook.presto.parquet.writer.ParquetWriter in project presto by prestodb.

the class ParquetTester method writeParquetFileFromPresto.

public static void writeParquetFileFromPresto(File outputFile, List<Type> types, List<String> columnNames, Iterator<?>[] values, int size, CompressionCodecName compressionCodecName) throws Exception {
    checkArgument(types.size() == columnNames.size() && types.size() == values.length);
    ParquetWriter writer = new ParquetWriter(new FileOutputStream(outputFile), columnNames, types, ParquetWriterOptions.builder().setMaxPageSize(DataSize.succinctBytes(100)).setMaxBlockSize(DataSize.succinctBytes(100000)).build(), compressionCodecName.getHadoopCompressionCodecClassName());
    PageBuilder pageBuilder = new PageBuilder(types);
    for (int i = 0; i < types.size(); ++i) {
        Type type = types.get(i);
        Iterator<?> iterator = values[i];
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
        for (int j = 0; j < size; ++j) {
            checkState(iterator.hasNext());
            Object value = iterator.next();
            writeValue(type, blockBuilder, value);
        }
    }
    pageBuilder.declarePositions(size);
    writer.write(pageBuilder.build());
    writer.close();
}
Also used : Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) DecimalType(com.facebook.presto.common.type.DecimalType) HiveUtil.isStructuralType(com.facebook.presto.hive.HiveUtil.isStructuralType) ArrayType(com.facebook.presto.common.type.ArrayType) CharType(com.facebook.presto.common.type.CharType) MetastoreUtil.isArrayType(com.facebook.presto.hive.metastore.MetastoreUtil.isArrayType) RowType(com.facebook.presto.common.type.RowType) MetastoreUtil.isRowType(com.facebook.presto.hive.metastore.MetastoreUtil.isRowType) VarcharType(com.facebook.presto.common.type.VarcharType) MessageType(org.apache.parquet.schema.MessageType) MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) MetastoreUtil.isMapType(com.facebook.presto.hive.metastore.MetastoreUtil.isMapType) ExampleParquetWriter(org.apache.parquet.hadoop.example.ExampleParquetWriter) ParquetWriter(com.facebook.presto.parquet.writer.ParquetWriter) FileOutputStream(java.io.FileOutputStream) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

PageBuilder (com.facebook.presto.common.PageBuilder)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 CharType (com.facebook.presto.common.type.CharType)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 MapType (com.facebook.presto.common.type.MapType)1 RowType (com.facebook.presto.common.type.RowType)1 Type (com.facebook.presto.common.type.Type)1 VarcharType (com.facebook.presto.common.type.VarcharType)1 Varchars.isVarcharType (com.facebook.presto.common.type.Varchars.isVarcharType)1 HiveUtil.isStructuralType (com.facebook.presto.hive.HiveUtil.isStructuralType)1 MetastoreUtil.isArrayType (com.facebook.presto.hive.metastore.MetastoreUtil.isArrayType)1 MetastoreUtil.isMapType (com.facebook.presto.hive.metastore.MetastoreUtil.isMapType)1 MetastoreUtil.isRowType (com.facebook.presto.hive.metastore.MetastoreUtil.isRowType)1 ParquetWriter (com.facebook.presto.parquet.writer.ParquetWriter)1 FileOutputStream (java.io.FileOutputStream)1 ExampleParquetWriter (org.apache.parquet.hadoop.example.ExampleParquetWriter)1 MessageType (org.apache.parquet.schema.MessageType)1