use of io.trino.spi.PageBuilder in project trino by trinodb.
the class PagePartitioner method partitionPageByRow.
public void partitionPageByRow(Page page) {
requireNonNull(page, "page is null");
if (page.getPositionCount() == 0) {
return;
}
int position;
// Handle "any row" replication outside of the inner loop processing
if (replicatesAnyRow && !hasAnyRowBeenReplicated) {
for (PageBuilder pageBuilder : pageBuilders) {
appendRow(pageBuilder, page, 0);
}
hasAnyRowBeenReplicated = true;
position = 1;
} else {
position = 0;
}
Page partitionFunctionArgs = getPartitionFunctionArguments(page);
// Skip null block checks if mayHaveNull reports that no positions will be null
if (nullChannel >= 0 && page.getBlock(nullChannel).mayHaveNull()) {
Block nullsBlock = page.getBlock(nullChannel);
for (; position < page.getPositionCount(); position++) {
if (nullsBlock.isNull(position)) {
for (PageBuilder pageBuilder : pageBuilders) {
appendRow(pageBuilder, page, position);
}
} else {
int partition = partitionFunction.getPartition(partitionFunctionArgs, position);
appendRow(pageBuilders[partition], page, position);
}
}
} else {
for (; position < page.getPositionCount(); position++) {
int partition = partitionFunction.getPartition(partitionFunctionArgs, position);
appendRow(pageBuilders[partition], page, position);
}
}
flush(false);
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class GenericPartitioningSpiller method partitionPage.
private synchronized IntArrayList partitionPage(Page page, IntPredicate spillPartitionMask) {
IntArrayList unspilledPositions = new IntArrayList();
for (int position = 0; position < page.getPositionCount(); position++) {
int partition = partitionFunction.getPartition(page, position);
if (!spillPartitionMask.test(partition)) {
unspilledPositions.add(position);
continue;
}
spilledPartitions.add(partition);
PageBuilder pageBuilder = pageBuilders.get(partition);
pageBuilder.declarePosition();
for (int channel = 0; channel < types.size(); channel++) {
Type type = types.get(channel);
type.appendTo(page.getBlock(channel), position, pageBuilder.getBlockBuilder(channel));
}
}
return unspilledPositions;
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class BenchmarkPageProcessor2 method rowOriented.
@Benchmark
public Page rowOriented() {
PageBuilder pageBuilder = new PageBuilder(types);
cursorProcessor.process(null, yieldSignal, recordSet.cursor(), pageBuilder);
return pageBuilder.build();
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class InMemoryHashAggregationBuilder method buildResult.
private WorkProcessor<Page> buildResult(IntIterator groupIds) {
PageBuilder pageBuilder = new PageBuilder(buildTypes());
return WorkProcessor.create(() -> {
if (!groupIds.hasNext()) {
return ProcessState.finished();
}
pageBuilder.reset();
List<Type> types = groupByHash.getTypes();
while (!pageBuilder.isFull() && groupIds.hasNext()) {
int groupId = groupIds.nextInt();
groupByHash.appendValuesTo(groupId, pageBuilder, 0);
pageBuilder.declarePosition();
for (int i = 0; i < groupedAggregators.size(); i++) {
GroupedAggregator groupedAggregator = groupedAggregators.get(i);
BlockBuilder output = pageBuilder.getBlockBuilder(types.size() + i);
groupedAggregator.evaluate(groupId, output);
}
}
return ProcessState.ofResult(pageBuilder.build());
});
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class TestDoubleHistogramAggregation method makeInput.
private static Page makeInput(int numberOfBuckets) {
PageBuilder builder = new PageBuilder(ImmutableList.of(BIGINT, DOUBLE, DOUBLE));
for (int i = 0; i < 100; i++) {
builder.declarePosition();
BIGINT.writeLong(builder.getBlockBuilder(0), numberOfBuckets);
// value
DOUBLE.writeDouble(builder.getBlockBuilder(1), i);
// weight
DOUBLE.writeDouble(builder.getBlockBuilder(2), 1);
}
return builder.build();
}
Aggregations