Search in sources :

Example 36 with PageBuilder

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

the class ZipWithFunction method zipWith.

public static Block zipWith(Type leftElementType, Type rightElementType, ArrayType outputArrayType, Object state, Block leftBlock, Block rightBlock, BinaryFunctionInterface function) {
    Type outputElementType = outputArrayType.getElementType();
    int leftPositionCount = leftBlock.getPositionCount();
    int rightPositionCount = rightBlock.getPositionCount();
    int outputPositionCount = max(leftPositionCount, rightPositionCount);
    PageBuilder pageBuilder = (PageBuilder) state;
    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }
    BlockBuilder arrayBlockBuilder = pageBuilder.getBlockBuilder(0);
    BlockBuilder blockBuilder = arrayBlockBuilder.beginBlockEntry();
    for (int position = 0; position < outputPositionCount; position++) {
        Object left = position < leftPositionCount ? readNativeValue(leftElementType, leftBlock, position) : null;
        Object right = position < rightPositionCount ? readNativeValue(rightElementType, rightBlock, position) : null;
        Object output;
        try {
            output = function.apply(left, right);
        } catch (Throwable throwable) {
            // Restore pageBuilder into a consistent state.
            arrayBlockBuilder.closeEntry();
            pageBuilder.declarePosition();
            throwIfUnchecked(throwable);
            throw new RuntimeException(throwable);
        }
        writeNativeValue(outputElementType, blockBuilder, output);
    }
    arrayBlockBuilder.closeEntry();
    pageBuilder.declarePosition();
    return outputArrayType.getObject(arrayBlockBuilder, arrayBlockBuilder.getPositionCount() - 1);
}
Also used : Type(io.trino.spi.type.Type) TypeSignature.functionType(io.trino.spi.type.TypeSignature.functionType) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) ArrayType(io.trino.spi.type.ArrayType) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 37 with PageBuilder

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

the class TableFinishOperator method getOutput.

@Override
public Page getOutput() {
    if (!isBlocked().isDone()) {
        return null;
    }
    if (!statisticsAggregationOperator.isFinished()) {
        verify(statisticsAggregationOperator.isBlocked().isDone(), "aggregation operator should not be blocked");
        OperationTimer timer = new OperationTimer(statisticsCpuTimerEnabled);
        Page page = statisticsAggregationOperator.getOutput();
        timer.end(statisticsTiming);
        if (page == null) {
            return null;
        }
        for (int position = 0; position < page.getPositionCount(); position++) {
            computedStatisticsBuilder.add(getComputedStatistics(page, position));
        }
        return null;
    }
    if (state != State.FINISHING) {
        return null;
    }
    state = State.FINISHED;
    this.outputMetadata.set(tableFinisher.finishTable(fragmentBuilder.build(), computedStatisticsBuilder.build(), tableExecuteContext));
    // output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder page = new PageBuilder(1, TYPES);
    if (outputRowCount) {
        page.declarePosition();
        BIGINT.writeLong(page.getBlockBuilder(0), rowCount);
    }
    return page.build();
}
Also used : Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder)

Example 38 with PageBuilder

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

the class TableWriterOperator method createFragmentsPage.

private Page createFragmentsPage() {
    Collection<Slice> fragments = getFutureValue(finishFuture);
    committed = true;
    updateWrittenBytes();
    // output page will only be constructed once,
    // so a new PageBuilder is constructed (instead of using PageBuilder.reset)
    PageBuilder page = new PageBuilder(fragments.size() + 1, ImmutableList.of(types.get(ROW_COUNT_CHANNEL), types.get(FRAGMENT_CHANNEL)));
    BlockBuilder rowsBuilder = page.getBlockBuilder(0);
    BlockBuilder fragmentBuilder = page.getBlockBuilder(1);
    // write row count
    page.declarePosition();
    BIGINT.writeLong(rowsBuilder, rowCount);
    fragmentBuilder.appendNull();
    // write fragments
    for (Slice fragment : fragments) {
        page.declarePosition();
        rowsBuilder.appendNull();
        VARBINARY.writeSlice(fragmentBuilder, fragment);
    }
    return page.build();
}
Also used : Slice(io.airlift.slice.Slice) PageBuilder(io.trino.spi.PageBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 39 with PageBuilder

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

the class PagesIndex method getSortedPages.

public Iterator<Page> getSortedPages() {
    return new AbstractIterator<>() {

        private int currentPosition;

        private final PageBuilder pageBuilder = new PageBuilder(types);

        private final int[] outputChannels = new int[types.size()];

        {
            Arrays.setAll(outputChannels, IntUnaryOperator.identity());
        }

        @Override
        public Page computeNext() {
            currentPosition = buildPage(currentPosition, outputChannels, pageBuilder);
            if (pageBuilder.isEmpty()) {
                return endOfData();
            }
            Page page = pageBuilder.build();
            pageBuilder.reset();
            return page;
        }
    };
}
Also used : Page(io.trino.spi.Page) AbstractIterator(com.google.common.collect.AbstractIterator) PageBuilder(io.trino.spi.PageBuilder)

Example 40 with PageBuilder

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

the class BenchmarkGroupByHash method bigintGroupByHash.

@Benchmark
@OperationsPerInvocation(POSITIONS)
public Object bigintGroupByHash(SingleChannelBenchmarkData data) {
    GroupByHash groupByHash = new BigintGroupByHash(0, data.getHashEnabled(), EXPECTED_SIZE, NOOP);
    addInputPagesToHash(groupByHash, data.getPages());
    ImmutableList.Builder<Page> pages = ImmutableList.builder();
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int groupId = 0; groupId < groupByHash.getGroupCount(); groupId++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(groupId, pageBuilder, 0);
        if (pageBuilder.isFull()) {
            pages.add(pageBuilder.build());
            pageBuilder.reset();
        }
    }
    pages.add(pageBuilder.build());
    return pageBuilder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) Benchmark(org.openjdk.jmh.annotations.Benchmark) OperationsPerInvocation(org.openjdk.jmh.annotations.OperationsPerInvocation)

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