Search in sources :

Example 21 with Page

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

the class NestedLoopJoinOperator method createNestedLoopOutputIterator.

@VisibleForTesting
static NestedLoopOutputIterator createNestedLoopOutputIterator(Page probePage, Page buildPage, int[] probeChannels, int[] buildChannels) {
    if (probeChannels.length == 0 && buildChannels.length == 0) {
        int probePositions = probePage.getPositionCount();
        int buildPositions = buildPage.getPositionCount();
        try {
            // positionCount is an int. Make sure the product can still fit in an int.
            int outputPositions = multiplyExact(probePositions, buildPositions);
            if (outputPositions <= PageProcessor.MAX_BATCH_SIZE) {
                return new PageRepeatingIterator(new Page(outputPositions), 1);
            }
        } catch (ArithmeticException overflow) {
        }
        // Repeat larger position count a smaller position count number of times
        Page outputPage = new Page(max(probePositions, buildPositions));
        return new PageRepeatingIterator(outputPage, min(probePositions, buildPositions));
    } else if (probeChannels.length == 0 && probePage.getPositionCount() <= buildPage.getPositionCount()) {
        return new PageRepeatingIterator(buildPage.getColumns(buildChannels), probePage.getPositionCount());
    } else if (buildChannels.length == 0 && buildPage.getPositionCount() <= probePage.getPositionCount()) {
        return new PageRepeatingIterator(probePage.getColumns(probeChannels), buildPage.getPositionCount());
    } else {
        return new NestedLoopPageBuilder(probePage, buildPage, probeChannels, buildChannels);
    }
}
Also used : Page(io.trino.spi.Page) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 22 with Page

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

the class NestedLoopJoinPagesBuilder method updatePagePositionCounter.

private void updatePagePositionCounter(int positions) {
    // Overflow should not be possible here since both arguments start as ints
    long nextPositionCount = addExact(this.emptyChannelPositionCounter, (long) positions);
    while (nextPositionCount >= PageProcessor.MAX_BATCH_SIZE) {
        nextPositionCount -= PageProcessor.MAX_BATCH_SIZE;
        Page flushed = new Page(PageProcessor.MAX_BATCH_SIZE);
        pages.add(flushed);
        estimatedSize += flushed.getRetainedSizeInBytes();
    }
    // Overflow should not occur since MAX_BATCH_SIZE is itself a positive integer
    this.emptyChannelPositionCounter = toIntExact(nextPositionCount);
}
Also used : Page(io.trino.spi.Page)

Example 23 with Page

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

the class NestedLoopJoinPagesBuilder method compact.

public void compact() {
    checkNotFinished();
    long estimatedSize = 0L;
    for (Page page : pages) {
        page.compact();
        estimatedSize += page.getRetainedSizeInBytes();
    }
    this.estimatedSize = estimatedSize;
}
Also used : Page(io.trino.spi.Page)

Example 24 with Page

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

the class NestedLoopJoinPagesBuilder method build.

public NestedLoopJoinPages build() {
    checkNotFinished();
    // Flush the position counter if we're in empty channels mode
    if (emptyChannelPositionCounter > 0) {
        Page output = new Page(emptyChannelPositionCounter);
        pages.add(output);
        estimatedSize += output.getRetainedSizeInBytes();
        this.emptyChannelPositionCounter = 0;
    }
    finished = true;
    pages = ImmutableList.copyOf(pages);
    return new NestedLoopJoinPages(pages, getEstimatedSize(), operatorContext);
}
Also used : Page(io.trino.spi.Page)

Example 25 with Page

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

the class LocalMergeSourceOperator method getOutput.

@Override
public Page getOutput() {
    if (!mergedPages.process() || mergedPages.isFinished()) {
        return null;
    }
    Page page = mergedPages.getResult();
    operatorContext.recordProcessedInput(page.getSizeInBytes(), page.getPositionCount());
    return page;
}
Also used : Page(io.trino.spi.Page)

Aggregations

Page (io.trino.spi.Page)579 Test (org.testng.annotations.Test)334 Block (io.trino.spi.block.Block)153 Type (io.trino.spi.type.Type)127 MaterializedResult (io.trino.testing.MaterializedResult)109 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)91 RowPagesBuilder (io.trino.RowPagesBuilder)72 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)68 ImmutableList (com.google.common.collect.ImmutableList)65 ArrayList (java.util.ArrayList)48 BlockBuilder (io.trino.spi.block.BlockBuilder)46 Optional (java.util.Optional)43 TaskContext (io.trino.operator.TaskContext)42 TestingTaskContext (io.trino.testing.TestingTaskContext)41 List (java.util.List)41 DictionaryBlock (io.trino.spi.block.DictionaryBlock)38 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)37 Slice (io.airlift.slice.Slice)36 OperatorFactory (io.trino.operator.OperatorFactory)32 LazyBlock (io.trino.spi.block.LazyBlock)32