Search in sources :

Example 11 with Page

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;
}
Also used : Page(io.trino.spi.Page)

Example 12 with 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;
}
Also used : MergeSortedPages.mergeSortedPages(io.trino.util.MergeSortedPages.mergeSortedPages) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) SettableFuture(com.google.common.util.concurrent.SettableFuture) Supplier(java.util.function.Supplier) DirectExchangeInput(io.trino.split.RemoteSplit.DirectExchangeInput) ArrayList(java.util.ArrayList) RemoteSplit(io.trino.split.RemoteSplit) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PagesSerdeFactory(io.trino.execution.buffer.PagesSerdeFactory) Closer(com.google.common.io.Closer) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Objects.requireNonNull(java.util.Objects.requireNonNull) URI(java.net.URI) IOException(java.io.IOException) MoreLists.mappedCopy(io.trino.util.MoreLists.mappedCopy) PagesSerde(io.trino.execution.buffer.PagesSerde) String.format(java.lang.String.format) SortOrder(io.trino.spi.connector.SortOrder) Preconditions.checkState(com.google.common.base.Preconditions.checkState) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Split(io.trino.metadata.Split) UpdatablePageSource(io.trino.spi.connector.UpdatablePageSource) Optional(java.util.Optional) ExchangeId(io.trino.spi.exchange.ExchangeId) RemoteSplit(io.trino.split.RemoteSplit) Page(io.trino.spi.Page) DirectExchangeInput(io.trino.split.RemoteSplit.DirectExchangeInput) ExchangeId(io.trino.spi.exchange.ExchangeId)

Example 13 with Page

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);
}
Also used : DictionaryBlock(io.trino.spi.block.DictionaryBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) Block(io.trino.spi.block.Block) LongArrayBlock(io.trino.spi.block.LongArrayBlock) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Page(io.trino.spi.Page)

Example 14 with Page

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;
}
Also used : Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder)

Example 15 with 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);
}
Also used : Verify.verifyNotNull(com.google.common.base.Verify.verifyNotNull) GeometrySerde.deserialize(io.trino.geospatial.serde.GeometrySerde.deserialize) Slice(io.airlift.slice.Slice) Rectangle(io.trino.geospatial.Rectangle) PageBuilder(io.trino.spi.PageBuilder) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) Type(io.trino.spi.type.Type) OptionalDouble(java.util.OptionalDouble) Page(io.trino.spi.Page) JoinUtils.channelsToPages(io.trino.operator.join.JoinUtils.channelsToPages) Block(io.trino.spi.block.Block) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Math.toIntExact(java.lang.Math.toIntExact) JoinFilterFunctionFactory(io.trino.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory) INTEGER(io.trino.spi.type.IntegerType.INTEGER) SyntheticAddress.decodePosition(io.trino.operator.SyntheticAddress.decodePosition) SpatialPredicate(io.trino.operator.SpatialIndexBuilderOperator.SpatialPredicate) JoinFilterFunction(io.trino.operator.join.JoinFilterFunction) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) Optional(java.util.Optional) SyntheticAddress.decodeSliceIndex(io.trino.operator.SyntheticAddress.decodeSliceIndex) Envelope(org.locationtech.jts.geom.Envelope) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Session(io.trino.Session) STRtree(org.locationtech.jts.index.strtree.STRtree) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCPoint(com.esri.core.geometry.ogc.OGCPoint) Slice(io.airlift.slice.Slice) Block(io.trino.spi.block.Block) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Envelope(org.locationtech.jts.geom.Envelope) OGCPoint(com.esri.core.geometry.ogc.OGCPoint)

Aggregations

Page (io.trino.spi.Page)579 Test (org.testng.annotations.Test)334 Block (io.trino.spi.block.Block)153 Type (io.trino.spi.type.Type)127 MaterializedResult (io.trino.testing.MaterializedResult)109 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)91 RowPagesBuilder (io.trino.RowPagesBuilder)72 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)68 ImmutableList (com.google.common.collect.ImmutableList)65 ArrayList (java.util.ArrayList)48 BlockBuilder (io.trino.spi.block.BlockBuilder)46 Optional (java.util.Optional)43 TaskContext (io.trino.operator.TaskContext)42 TestingTaskContext (io.trino.testing.TestingTaskContext)41 List (java.util.List)41 DictionaryBlock (io.trino.spi.block.DictionaryBlock)38 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)37 Slice (io.airlift.slice.Slice)36 OperatorFactory (io.trino.operator.OperatorFactory)32 LazyBlock (io.trino.spi.block.LazyBlock)32