use of io.trino.spi.Page in project trino by trinodb.
the class MergeOperator method getOutput.
@Override
public Page getOutput() {
if (closed || mergedPages == null || !mergedPages.process() || mergedPages.isFinished()) {
return null;
}
Page page = mergedPages.getResult();
operatorContext.recordProcessedInput(page.getSizeInBytes(), page.getPositionCount());
return page;
}
use of io.trino.spi.Page in project trino by trinodb.
the class MergeOperator method addSplit.
@Override
public Supplier<Optional<UpdatablePageSource>> addSplit(Split split) {
requireNonNull(split, "split is null");
checkArgument(split.getConnectorSplit() instanceof RemoteSplit, "split is not a remote split");
checkState(!blockedOnSplits.isDone(), "noMoreSplits has been called already");
TaskContext taskContext = operatorContext.getDriverContext().getPipelineContext().getTaskContext();
DirectExchangeClient client = closer.register(directExchangeClientSupplier.get(taskContext.getTaskId().getQueryId(), new ExchangeId(format("direct-exchange-merge-%s-%s", taskContext.getTaskId().getStageId().getId(), sourceId)), operatorContext.localUserMemoryContext(), taskContext::sourceTaskFailed, RetryPolicy.NONE));
RemoteSplit remoteSplit = (RemoteSplit) split.getConnectorSplit();
// Only fault tolerant execution mode is expected to execute external exchanges.
// MergeOperator is used for distributed sort only and it is not compatible (and disabled) with fault tolerant execution mode.
DirectExchangeInput exchangeInput = (DirectExchangeInput) remoteSplit.getExchangeInput();
client.addLocation(exchangeInput.getTaskId(), URI.create(exchangeInput.getLocation()));
client.noMoreLocations();
pageProducers.add(client.pages().map(serializedPage -> {
Page page = pagesSerde.deserialize(serializedPage);
operatorContext.recordNetworkInput(serializedPage.length(), page.getPositionCount());
return page;
}));
return Optional::empty;
}
use of io.trino.spi.Page in project trino by trinodb.
the class MultiChannelGroupByHash method createPageWithExtractedDictionary.
// For a page that contains DictionaryBlocks, create a new page in which
// the dictionaries from the DictionaryBlocks are extracted into the corresponding channels
// From Page(DictionaryBlock1, DictionaryBlock2) create new page with Page(dictionary1, dictionary2)
private Page createPageWithExtractedDictionary(Page page) {
Block[] blocks = new Block[page.getChannelCount()];
Block dictionary = ((DictionaryBlock) page.getBlock(channels[0])).getDictionary();
// extract data dictionary
blocks[channels[0]] = dictionary;
// extract hash dictionary
inputHashChannel.ifPresent(integer -> blocks[integer] = ((DictionaryBlock) page.getBlock(integer)).getDictionary());
return new Page(dictionary.getPositionCount(), blocks);
}
use of io.trino.spi.Page 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.Page in project trino by trinodb.
the class PagesRTreeIndex method findJoinPositions.
/**
* Returns an array of addresses from {@link PagesIndex#valueAddresses} corresponding
* to rows with matching geometries.
* <p>
* The caller is responsible for calling {@link #isJoinPositionEligible(int, int, Page)}
* for each of these addresses to apply additional join filters.
*/
@Override
public int[] findJoinPositions(int probePosition, Page probe, int probeGeometryChannel, Optional<Integer> probePartitionChannel) {
Block probeGeometryBlock = probe.getBlock(probeGeometryChannel);
if (probeGeometryBlock.isNull(probePosition)) {
return EMPTY_ADDRESSES;
}
int probePartition = probePartitionChannel.map(channel -> toIntExact(INTEGER.getLong(probe.getBlock(channel), probePosition))).orElse(-1);
Slice slice = probeGeometryBlock.getSlice(probePosition, 0, probeGeometryBlock.getSliceLength(probePosition));
OGCGeometry probeGeometry = deserialize(slice);
verifyNotNull(probeGeometry);
if (probeGeometry.isEmpty()) {
return EMPTY_ADDRESSES;
}
boolean probeIsPoint = probeGeometry instanceof OGCPoint;
IntArrayList matchingPositions = new IntArrayList();
Envelope envelope = getEnvelope(probeGeometry);
rtree.query(envelope, item -> {
GeometryWithPosition geometryWithPosition = (GeometryWithPosition) item;
OGCGeometry buildGeometry = geometryWithPosition.getGeometry();
if (partitions.isEmpty() || (probePartition == geometryWithPosition.getPartition() && (probeIsPoint || (buildGeometry instanceof OGCPoint) || testReferencePoint(envelope, buildGeometry, probePartition)))) {
if (radiusChannel == -1) {
if (spatialRelationshipTest.apply(buildGeometry, probeGeometry, OptionalDouble.empty())) {
matchingPositions.add(geometryWithPosition.getPosition());
}
} else {
if (spatialRelationshipTest.apply(geometryWithPosition.getGeometry(), probeGeometry, OptionalDouble.of(getRadius(geometryWithPosition.getPosition())))) {
matchingPositions.add(geometryWithPosition.getPosition());
}
}
}
});
return matchingPositions.toIntArray(null);
}
Aggregations