use of io.trino.spi.PageBuilder in project trino by trinodb.
the class ArrayConcatFunction method concat.
@UsedByGeneratedCode
public static Block concat(Type elementType, Object state, Block[] blocks) {
int resultPositionCount = 0;
// fast path when there is at most one non empty block
Block nonEmptyBlock = null;
for (int i = 0; i < blocks.length; i++) {
resultPositionCount += blocks[i].getPositionCount();
if (blocks[i].getPositionCount() > 0) {
nonEmptyBlock = blocks[i];
}
}
if (nonEmptyBlock == null) {
return blocks[0];
}
if (resultPositionCount == nonEmptyBlock.getPositionCount()) {
return nonEmptyBlock;
}
PageBuilder pageBuilder = (PageBuilder) state;
if (pageBuilder.isFull()) {
pageBuilder.reset();
}
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);
for (int blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
Block block = blocks[blockIndex];
for (int i = 0; i < block.getPositionCount(); i++) {
elementType.appendTo(block, i, blockBuilder);
}
}
pageBuilder.declarePositions(resultPositionCount);
return blockBuilder.getRegion(blockBuilder.getPositionCount() - resultPositionCount, resultPositionCount);
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class PagePartitioner method flush.
public void flush(boolean force) {
try (PagesSerde.PagesSerdeContext context = serde.newContext()) {
// add all full pages to output buffer
for (int partition = 0; partition < pageBuilders.length; partition++) {
PageBuilder partitionPageBuilder = pageBuilders[partition];
if (!partitionPageBuilder.isEmpty() && (force || partitionPageBuilder.isFull())) {
Page pagePartition = partitionPageBuilder.build();
partitionPageBuilder.reset();
operatorContext.recordOutput(pagePartition.getSizeInBytes(), pagePartition.getPositionCount());
outputBuffer.enqueue(partition, splitAndSerializePage(context, pagePartition));
pagesAdded.incrementAndGet();
rowsAdded.addAndGet(pagePartition.getPositionCount());
}
}
}
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class RowNumberOperator method getSelectedRows.
private Page getSelectedRows() {
verify(selectedRowPageBuilder.isPresent());
int rowNumberChannel = types.size() - 1;
PageBuilder pageBuilder = selectedRowPageBuilder.get();
verify(pageBuilder.isEmpty());
for (int currentPosition = 0; currentPosition < inputPage.getPositionCount(); currentPosition++) {
long partitionId = getPartitionId(currentPosition);
long rowCount = partitionRowCount.get(partitionId);
if (rowCount == maxRowsPerPartition.get()) {
continue;
}
pageBuilder.declarePosition();
for (int i = 0; i < outputChannels.length; i++) {
int channel = outputChannels[i];
Type type = types.get(i);
type.appendTo(inputPage.getBlock(channel), currentPosition, pageBuilder.getBlockBuilder(i));
}
BIGINT.writeLong(pageBuilder.getBlockBuilder(rowNumberChannel), rowCount + 1);
partitionRowCount.set(partitionId, rowCount + 1);
}
if (pageBuilder.isEmpty()) {
return null;
}
Page page = pageBuilder.build();
pageBuilder.reset();
return page;
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class HashAggregationOperator method getGlobalAggregationOutput.
private Page getGlobalAggregationOutput() {
// global aggregation output page will only be constructed once,
// so a new PageBuilder is constructed (instead of using PageBuilder.reset)
PageBuilder output = new PageBuilder(globalAggregationGroupIds.size(), types);
for (int groupId : globalAggregationGroupIds) {
output.declarePosition();
int channel = 0;
while (channel < groupByTypes.size()) {
if (channel == groupIdChannel.orElseThrow()) {
output.getBlockBuilder(channel).writeLong(groupId);
} else {
output.getBlockBuilder(channel).appendNull();
}
channel++;
}
if (hashChannel.isPresent()) {
long hashValue = calculateDefaultOutputHash(groupByTypes, groupIdChannel.orElseThrow(), groupId);
output.getBlockBuilder(channel).writeLong(hashValue);
channel++;
}
for (AggregatorFactory aggregatorFactory : aggregatorFactories) {
aggregatorFactory.createAggregator().evaluate(output.getBlockBuilder(channel));
channel++;
}
}
if (output.isEmpty()) {
return null;
}
return output.build();
}
use of io.trino.spi.PageBuilder in project trino by trinodb.
the class GenericPartitioningSpiller method flush.
private synchronized ListenableFuture<Void> flush(int partition) {
PageBuilder pageBuilder = pageBuilders.get(partition);
if (pageBuilder.isEmpty()) {
return immediateVoidFuture();
}
Page page = pageBuilder.build();
pageBuilder.reset();
return getSpiller(partition).spill(page);
}
Aggregations