Search in sources :

Example 26 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class PagesIndex method appendTo.

public void appendTo(int channel, int position, BlockBuilder output) {
    long pageAddress = valueAddresses.getLong(position);
    Type type = types.get(channel);
    Block block = channels[channel].get(decodeSliceIndex(pageAddress));
    int blockPosition = decodePosition(pageAddress);
    type.appendTo(block, blockPosition, output);
}
Also used : Type(io.trino.spi.type.Type) Block(io.trino.spi.block.Block)

Example 27 with Block

use of io.trino.spi.block.Block 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)

Example 28 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class PagesIndex method compact.

public void compact() {
    if (eagerCompact || channels.length == 0) {
        return;
    }
    for (int channel = 0; channel < types.size(); channel++) {
        ObjectArrayList<Block> blocks = channels[channel];
        for (int i = nextBlockToCompact; i < blocks.size(); i++) {
            Block block = blocks.get(i);
            // Copy the block to compact its size
            Block compactedBlock = block.copyRegion(0, block.getPositionCount());
            blocks.set(i, compactedBlock);
            pagesMemorySize -= block.getRetainedSizeInBytes();
            pagesMemorySize += compactedBlock.getRetainedSizeInBytes();
        }
    }
    nextBlockToCompact = channels[0].size();
    estimatedSize = calculateEstimatedSize();
}
Also used : Block(io.trino.spi.block.Block)

Example 29 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class PagesIndex method getSlice.

public Slice getSlice(int channel, int position) {
    long pageAddress = valueAddresses.getLong(position);
    Block block = channels[channel].get(decodeSliceIndex(pageAddress));
    int blockPosition = decodePosition(pageAddress);
    return types.get(channel).getSlice(block, blockPosition);
}
Also used : Block(io.trino.spi.block.Block)

Example 30 with Block

use of io.trino.spi.block.Block in project trino by trinodb.

the class PagesIndex method getBoolean.

public boolean getBoolean(int channel, int position) {
    long pageAddress = valueAddresses.getLong(position);
    Block block = channels[channel].get(decodeSliceIndex(pageAddress));
    int blockPosition = decodePosition(pageAddress);
    return types.get(channel).getBoolean(block, blockPosition);
}
Also used : Block(io.trino.spi.block.Block)

Aggregations

Block (io.trino.spi.block.Block)520 Test (org.testng.annotations.Test)161 Page (io.trino.spi.Page)145 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)107 BlockBuilder (io.trino.spi.block.BlockBuilder)105 DictionaryBlock (io.trino.spi.block.DictionaryBlock)103 Type (io.trino.spi.type.Type)89 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)65 Slice (io.airlift.slice.Slice)61 TrinoException (io.trino.spi.TrinoException)41 BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)39 LazyBlock (io.trino.spi.block.LazyBlock)37 ArrayType (io.trino.spi.type.ArrayType)31 RowType (io.trino.spi.type.RowType)31 ArrayList (java.util.ArrayList)31 LongArrayBlock (io.trino.spi.block.LongArrayBlock)29 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)28 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)26 ImmutableList (com.google.common.collect.ImmutableList)25 DecimalType (io.trino.spi.type.DecimalType)25