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