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);
}
}
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);
}
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;
}
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);
}
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;
}
Aggregations