Search in sources :

Example 6 with OutputStreamDataSink

use of com.facebook.presto.common.io.OutputStreamDataSink in project presto by prestodb.

the class TestStructBatchStreamReader method write.

private void write(TempFile tempFile, Type writerType, List<String> data) throws IOException {
    OrcWriter writer = new OrcWriter(new OutputStreamDataSink(new FileOutputStream(tempFile.getFile())), ImmutableList.of(STRUCT_COL_NAME), ImmutableList.of(writerType), ORC, NONE, Optional.empty(), NO_ENCRYPTION, OrcWriterOptions.builder().withFlushPolicy(DefaultOrcWriterFlushPolicy.builder().withStripeMinSize(new DataSize(0, MEGABYTE)).withStripeMaxSize(new DataSize(32, MEGABYTE)).withStripeMaxRowCount(ORC_STRIPE_SIZE).build()).withRowGroupMaxRowCount(ORC_ROW_GROUP_SIZE).withDictionaryMaxMemory(new DataSize(32, MEGABYTE)).build(), ImmutableMap.of(), HIVE_STORAGE_TIME_ZONE, true, BOTH, new OrcWriterStats());
    // write down some data with unsorted streams
    Block[] fieldBlocks = new Block[data.size()];
    int entries = 10;
    boolean[] rowIsNull = new boolean[entries];
    Arrays.fill(rowIsNull, false);
    BlockBuilder blockBuilder = TEST_DATA_TYPE.createBlockBuilder(null, entries);
    for (int i = 0; i < data.size(); i++) {
        byte[] bytes = data.get(i).getBytes();
        for (int j = 0; j < entries; j++) {
            blockBuilder.writeBytes(Slices.wrappedBuffer(bytes), 0, bytes.length);
            blockBuilder.closeEntry();
        }
        fieldBlocks[i] = blockBuilder.build();
        blockBuilder = blockBuilder.newBlockBuilderLike(null);
    }
    Block rowBlock = RowBlock.fromFieldBlocks(rowIsNull.length, Optional.of(rowIsNull), fieldBlocks);
    writer.write(new Page(rowBlock));
    writer.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) DataSize(io.airlift.units.DataSize) RowBlock(com.facebook.presto.common.block.RowBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) OutputStreamDataSink(com.facebook.presto.common.io.OutputStreamDataSink) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

OutputStreamDataSink (com.facebook.presto.common.io.OutputStreamDataSink)6 Page (com.facebook.presto.common.Page)4 FileOutputStream (java.io.FileOutputStream)4 Block (com.facebook.presto.common.block.Block)3 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)3 Type (com.facebook.presto.common.type.Type)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)1 RowBlock (com.facebook.presto.common.block.RowBlock)1 DataSink (com.facebook.presto.common.io.DataSink)1 TypeManager (com.facebook.presto.common.type.TypeManager)1 FileFormatDataSourceStats (com.facebook.presto.hive.FileFormatDataSourceStats)1 HdfsContext (com.facebook.presto.hive.HdfsContext)1 HdfsEnvironment (com.facebook.presto.hive.HdfsEnvironment)1 HiveDwrfEncryptionProvider (com.facebook.presto.hive.HiveDwrfEncryptionProvider)1 PRESTO_VERSION_NAME (com.facebook.presto.hive.HiveMetadata.PRESTO_VERSION_NAME)1 HiveSessionProperties (com.facebook.presto.hive.HiveSessionProperties)1 HiveSessionProperties.getParquetWriterBlockSize (com.facebook.presto.hive.HiveSessionProperties.getParquetWriterBlockSize)1 HiveSessionProperties.getParquetWriterPageSize (com.facebook.presto.hive.HiveSessionProperties.getParquetWriterPageSize)1 NodeVersion (com.facebook.presto.hive.NodeVersion)1