Search in sources :

Example 1 with PageBuilder

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

the class ArrayConcatFunction method concat.

@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
    int resultPositionCount = 0;
    // fast path when there is at most one non empty block
    Block nonEmptyBlock = null;
    for (int i = 0; i < blocks.length; i++) {
        resultPositionCount += blocks[i].getPositionCount();
        if (blocks[i].getPositionCount() > 0) {
            nonEmptyBlock = blocks[i];
        }
    }
    if (nonEmptyBlock == null) {
        return blocks[0];
    }
    if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
        return nonEmptyBlock;
    }
    PageBuilder pageBuilder = (PageBuilder) state;
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
    for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
        Block block = blocks[blockIndex];
        for (int i = 0; i < block.getPositionCount(); i++) {
            elementType.appendTo(block, i, blockBuilder);
        }
    }
    pageBuilder.declarePositions(resultPositionCount);
    return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
Also used : Block(io.trino.spi.block.Block) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Example 2 with PageBuilder

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

the class PagePartitioner method flush.

public void flush(boolean force) {
    try (PagesSerde.PagesSerdeContext context = serde.newContext()) {
        // add all full pages to output buffer
        for (int partition = 0; partition < pageBuilders.length; partition++) {
            PageBuilder partitionPageBuilder = pageBuilders[partition];
            if (!partitionPageBuilder.isEmpty() && (force || partitionPageBuilder.isFull())) {
                Page pagePartition = partitionPageBuilder.build();
                partitionPageBuilder.reset();
                operatorContext.recordOutput(pagePartition.getSizeInBytes(), pagePartition.getPositionCount());
                outputBuffer.enqueue(partition, splitAndSerializePage(context, pagePartition));
                pagesAdded.incrementAndGet();
                rowsAdded.addAndGet(pagePartition.getPositionCount());
            }
        }
    }
}
Also used : PagesSerde(io.trino.execution.buffer.PagesSerde) Page(io.trino.spi.Page) PageSplitterUtil.splitPage(io.trino.execution.buffer.PageSplitterUtil.splitPage) PageBuilder(io.trino.spi.PageBuilder)

Example 3 with PageBuilder

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

the class RowNumberOperator method getSelectedRows.

private Page getSelectedRows() {
    verify(selectedRowPageBuilder.isPresent());
    int rowNumberChannel = types.size() - 1;
    PageBuilder pageBuilder = selectedRowPageBuilder.get();
    verify(pageBuilder.isEmpty());
    for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) {
        long partitionId = getPartitionId(currentPosition);
        long rowCount = partitionRowCount.get(partitionId);
        if (rowCount == maxRowsPerPartition.get()) {
            continue;
        }
        pageBuilder.declarePosition();
        for (int i = 0; i < outputChannels.length; i++) {
            int channel = outputChannels[i];
            Type type = types.get(i);
            type.appendTo(inputPage.getBlock(channel), currentPosition, pageBuilder.getBlockBuilder(i));
        }
        BIGINT.writeLong(pageBuilder.getBlockBuilder(rowNumberChannel), rowCount + 1);
        partitionRowCount.set(partitionId, rowCount + 1);
    }
    if (pageBuilder.isEmpty()) {
        return null;
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    return page;
}
Also used : Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder)

Example 4 with PageBuilder

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

the class HashAggregationOperator method getGlobalAggregationOutput.

private Page getGlobalAggregationOutput() {
    // global aggregation output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder output = new PageBuilder(globalAggregationGroupIds.size(), types);
    for (int groupId : globalAggregationGroupIds) {
        output.declarePosition();
        int channel = 0;
        while (channel < groupByTypes.size()) {
            if (channel == groupIdChannel.orElseThrow()) {
                output.getBlockBuilder(channel).writeLong(groupId);
            } else {
                output.getBlockBuilder(channel).appendNull();
            }
            channel++;
        }
        if (hashChannel.isPresent()) {
            long hashValue = calculateDefaultOutputHash(groupByTypes, groupIdChannel.orElseThrow(), groupId);
            output.getBlockBuilder(channel).writeLong(hashValue);
            channel++;
        }
        for (AggregatorFactory aggregatorFactory : aggregatorFactories) {
            aggregatorFactory.createAggregator().evaluate(output.getBlockBuilder(channel));
            channel++;
        }
    }
    if (output.isEmpty()) {
        return null;
    }
    return output.build();
}
Also used : PageBuilder(io.trino.spi.PageBuilder) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory)

Example 5 with PageBuilder

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

the class GenericPartitioningSpiller method flush.

private synchronized ListenableFuture<Void> flush(int partition) {
    PageBuilder pageBuilder = pageBuilders.get(partition);
    if (pageBuilder.isEmpty()) {
        return immediateVoidFuture();
    }
    Page page = pageBuilder.build();
    pageBuilder.reset();
    return getSpiller(partition).spill(page);
}
Also used : Page(io.trino.spi.Page) 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