Search in sources :

Example 41 with PageBuilder

use of com.facebook.presto.common.PageBuilder 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)

Example 42 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class InMemoryHashAggregationBuilder method buildResult.

private WorkProcessor<Page> buildResult(IntIterator groupIds) {
    final PageBuilder pageBuilder = new PageBuilder(buildTypes());
    return WorkProcessor.create(() -> {
        if (!groupIds.hasNext()) {
            return ProcessState.finished();
        }
        pageBuilder.reset();
        List<Type> types = groupByHash.getTypes();
        while (!pageBuilder.isFull() && groupIds.hasNext()) {
            int groupId = groupIds.nextInt();
            groupByHash.appendValuesTo(groupId, pageBuilder, 0);
            pageBuilder.declarePosition();
            for (int i = 0; i < aggregators.size(); i++) {
                Aggregator aggregator = aggregators.get(i);
                BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
                aggregator.evaluate(groupId, output);
            }
        }
        return ProcessState.ofResult(pageBuilder.build());
    });
}
Also used : Type(com.facebook.presto.common.type.Type) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Example 43 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class GenericPartitioningSpiller method partitionPage.

private synchronized IntArrayList partitionPage(Page page, IntPredicate spillPartitionMask) {
    IntArrayList unspilledPositions = new IntArrayList();
    for (int position = 0; position < page.getPositionCount(); position++) {
        int partition = partitionFunction.getPartition(page, position);
        if (!spillPartitionMask.test(partition)) {
            unspilledPositions.add(position);
            continue;
        }
        spilledPartitions.add(partition);
        PageBuilder pageBuilder = pageBuilders[partition];
        pageBuilder.declarePosition();
        for (int channel = 0; channel < types.size(); channel++) {
            Type type = types.get(channel);
            type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
        }
    }
    return unspilledPositions;
}
Also used : Type(com.facebook.presto.common.type.Type) PageBuilder(com.facebook.presto.common.PageBuilder) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 44 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class GenericPartitioningSpiller method flush.

private synchronized ListenableFuture<?> flush(int partition) {
    PageBuilder pageBuilder = pageBuilders[partition];
    if (pageBuilder.isEmpty()) {
        return Futures.immediateFuture(null);
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    return getSpiller(partition).spill(page);
}
Also used : Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder)

Example 45 with PageBuilder

use of com.facebook.presto.common.PageBuilder in project presto by prestodb.

the class PageAssertions method mergePages.

public static Page mergePages(List<Type> types, List<Page> pages) {
    PageBuilder pageBuilder = new PageBuilder(types);
    int totalPositionCount = 0;
    for (Page page : pages) {
        verify(page.getChannelCount() == types.size(), format("Number of channels in page %d is not equal to number of types %d", page.getChannelCount(), types.size()));
        for (int i = 0; i < types.size(); i++) {
            BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
            Block block = page.getBlock(i);
            for (int position = 0; position < page.getPositionCount(); position++) {
                if (block.isNull(position)) {
                    blockBuilder.appendNull();
                } else {
                    block.writePositionTo(position, blockBuilder);
                }
            }
        }
        totalPositionCount += page.getPositionCount();
    }
    pageBuilder.declarePositions(totalPositionCount);
    return pageBuilder.build();
}
Also used : BlockAssertions.createAllNullsBlock(com.facebook.presto.block.BlockAssertions.createAllNullsBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) PageBuilder(com.facebook.presto.common.PageBuilder) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

PageBuilder (com.facebook.presto.common.PageBuilder)57 Page (com.facebook.presto.common.Page)27 Type (com.facebook.presto.common.type.Type)25 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)23 ImmutableList (com.google.common.collect.ImmutableList)14 Block (com.facebook.presto.common.block.Block)11 Test (org.testng.annotations.Test)11 ArrayType (com.facebook.presto.common.type.ArrayType)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Benchmark (org.openjdk.jmh.annotations.Benchmark)7 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)3 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)3 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)3 ConnectorSession (com.facebook.presto.spi.ConnectorSession)3 MaterializedResult (com.facebook.presto.testing.MaterializedResult)3 Slices (io.airlift.slice.Slices)3 File (java.io.File)3