Search in sources :

Example 1 with ParquetWriter

use of io.trino.parquet.writer.ParquetWriter in project trino by trinodb.

the class ParquetTester method writeParquetColumnTrino.

private static void writeParquetColumnTrino(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);
    ParquetSchemaConverter schemaConverter = new ParquetSchemaConverter(types, columnNames);
    ParquetWriter writer = new ParquetWriter(new FileOutputStream(outputFile), schemaConverter.getMessageType(), schemaConverter.getPrimitiveTypes(), ParquetWriterOptions.builder().setMaxPageSize(DataSize.ofBytes(100)).setMaxBlockSize(DataSize.ofBytes(100000)).build(), compressionCodecName, "test-version");
    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 : HiveUtil.isMapType(io.trino.plugin.hive.util.HiveUtil.isMapType) HiveUtil.isRowType(io.trino.plugin.hive.util.HiveUtil.isRowType) MapType(io.trino.spi.type.MapType) CharType(io.trino.spi.type.CharType) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) MessageType(org.apache.parquet.schema.MessageType) DecimalType(io.trino.spi.type.DecimalType) Type(io.trino.spi.type.Type) VarcharType(io.trino.spi.type.VarcharType) HiveUtil.isArrayType(io.trino.plugin.hive.util.HiveUtil.isArrayType) HiveUtil.isStructuralType(io.trino.plugin.hive.util.HiveUtil.isStructuralType) ParquetWriter(io.trino.parquet.writer.ParquetWriter) FileOutputStream(java.io.FileOutputStream) PageBuilder(io.trino.spi.PageBuilder) ParquetSchemaConverter(io.trino.parquet.writer.ParquetSchemaConverter) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

ParquetSchemaConverter (io.trino.parquet.writer.ParquetSchemaConverter)1 ParquetWriter (io.trino.parquet.writer.ParquetWriter)1 HiveUtil.isArrayType (io.trino.plugin.hive.util.HiveUtil.isArrayType)1 HiveUtil.isMapType (io.trino.plugin.hive.util.HiveUtil.isMapType)1 HiveUtil.isRowType (io.trino.plugin.hive.util.HiveUtil.isRowType)1 HiveUtil.isStructuralType (io.trino.plugin.hive.util.HiveUtil.isStructuralType)1 PageBuilder (io.trino.spi.PageBuilder)1 BlockBuilder (io.trino.spi.block.BlockBuilder)1 ArrayType (io.trino.spi.type.ArrayType)1 CharType (io.trino.spi.type.CharType)1 DecimalType (io.trino.spi.type.DecimalType)1 MapType (io.trino.spi.type.MapType)1 RowType (io.trino.spi.type.RowType)1 Type (io.trino.spi.type.Type)1 VarcharType (io.trino.spi.type.VarcharType)1 FileOutputStream (java.io.FileOutputStream)1 MessageType (org.apache.parquet.schema.MessageType)1