Search in sources :

Example 46 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class PagePartitioner method partitionPageByRow.

public void partitionPageByRow(Page page) {
    requireNonNull(page, "page is null");
    if (page.getPositionCount() == 0) {
        return;
    }
    int position;
    // Handle "any row" replication outside of the inner loop processing
    if (replicatesAnyRow && !hasAnyRowBeenReplicated) {
        for (PageBuilder pageBuilder : pageBuilders) {
            appendRow(pageBuilder, page, 0);
        }
        hasAnyRowBeenReplicated = true;
        position = 1;
    } else {
        position = 0;
    }
    Page partitionFunctionArgs = getPartitionFunctionArguments(page);
    // Skip null block checks if mayHaveNull reports that no positions will be null
    if (nullChannel >= 0 && page.getBlock(nullChannel).mayHaveNull()) {
        Block nullsBlock = page.getBlock(nullChannel);
        for (; position < page.getPositionCount(); position++) {
            if (nullsBlock.isNull(position)) {
                for (PageBuilder pageBuilder : pageBuilders) {
                    appendRow(pageBuilder, page, position);
                }
            } else {
                int partition = partitionFunction.getPartition(partitionFunctionArgs, position);
                appendRow(pageBuilders[partition], page, position);
            }
        }
    } else {
        for (; position < page.getPositionCount(); position++) {
            int partition = partitionFunction.getPartition(partitionFunctionArgs, position);
            appendRow(pageBuilders[partition], page, position);
        }
    }
    flush(false);
}
Also used : DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Page(io.trino.spi.Page) PageSplitterUtil.splitPage(io.trino.execution.buffer.PageSplitterUtil.splitPage) PageBuilder(io.trino.spi.PageBuilder)

Example 47 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

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.get(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(io.trino.spi.type.Type) PageBuilder(io.trino.spi.PageBuilder) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 48 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class BenchmarkPageProcessor2 method rowOriented.

@Benchmark
public Page rowOriented() {
    PageBuilder pageBuilder = new PageBuilder(types);
    cursorProcessor.process(null, yieldSignal, recordSet.cursor(), pageBuilder);
    return pageBuilder.build();
}
Also used : PageBuilder(io.trino.spi.PageBuilder) SequencePageBuilder(io.trino.SequencePageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 49 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class InMemoryHashAggregationBuilder method buildResult.

private WorkProcessor<Page> buildResult(IntIterator groupIds) {
    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 < groupedAggregators.size(); i++) {
                GroupedAggregator groupedAggregator = groupedAggregators.get(i);
                BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
                groupedAggregator.evaluate(groupId, output);
            }
        }
        return ProcessState.ofResult(pageBuilder.build());
    });
}
Also used : Type(io.trino.spi.type.Type) GroupedAggregator(io.trino.operator.aggregation.GroupedAggregator) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 50 with PageBuilder

use of io.trino.spi.PageBuilder in project trino by trinodb.

the class TestDoubleHistogramAggregation method makeInput.

private static Page makeInput(int numberOfBuckets) {
    PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, DOUBLE, DOUBLE));
    for (int i = 0; i < 100; i++) {
        builder.declarePosition();
        BIGINT.writeLong(builder.getBlockBuilder(0), numberOfBuckets);
        // value
        DOUBLE.writeDouble(builder.getBlockBuilder(1), i);
        // weight
        DOUBLE.writeDouble(builder.getBlockBuilder(2), 1);
    }
    return builder.build();
}
Also used : PageBuilder(io.trino.spi.PageBuilder)

Aggregations

PageBuilder (io.trino.spi.PageBuilder)58 BlockBuilder (io.trino.spi.block.BlockBuilder)24 Page (io.trino.spi.Page)23 Type (io.trino.spi.type.Type)22 ImmutableList (com.google.common.collect.ImmutableList)14 Block (io.trino.spi.block.Block)11 Test (org.testng.annotations.Test)10 List (java.util.List)8 Slice (io.airlift.slice.Slice)6 ArrayType (io.trino.spi.type.ArrayType)6 INTEGER (io.trino.spi.type.IntegerType.INTEGER)5 Slices (io.airlift.slice.Slices)4 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)4 DictionaryBlock (io.trino.spi.block.DictionaryBlock)4 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)4 BIGINT (io.trino.spi.type.BigintType.BIGINT)4 DOUBLE (io.trino.spi.type.DoubleType.DOUBLE)4 MapType (io.trino.spi.type.MapType)4 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)4 RowType (io.trino.spi.type.RowType)3