Search in sources :

Example 1 with AdaptiveLongBigArray

use of com.facebook.presto.common.array.AdaptiveLongBigArray in project presto by prestodb.

the class SimplePagesIndexComparator method compareTo.

@Override
public int compareTo(PagesIndex pagesIndex, int leftPosition, int rightPosition) {
    AdaptiveLongBigArray valueAddresses = pagesIndex.getValueAddresses();
    long leftPageAddress = valueAddresses.get(leftPosition);
    long rightPageAddress = valueAddresses.get(rightPosition);
    int leftBlockIndex = decodeSliceIndex(leftPageAddress);
    int leftBlockPosition = decodePosition(leftPageAddress);
    int rightBlockIndex = decodeSliceIndex(rightPageAddress);
    int rightBlockPosition = decodePosition(rightPageAddress);
    for (int i = 0; i < sortChannels.length; i++) {
        int sortChannel = sortChannels[i];
        SortOrder sortOrder = sortOrders[i];
        Type sortType = sortTypes[i];
        List<Block> indexChannel = pagesIndex.getChannel(sortChannel);
        Block leftBlock = indexChannel.get(leftBlockIndex);
        Block rightBlock = indexChannel.get(rightBlockIndex);
        try {
            int compare = sortOrder.compareBlockValue(sortType, leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
            if (compare != 0) {
                return compare;
            }
        } catch (NotSupportedException e) {
            throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
        }
    }
    return 0;
}
Also used : Type(com.facebook.presto.common.type.Type) SortOrder(com.facebook.presto.common.block.SortOrder) Block(com.facebook.presto.common.block.Block) PrestoException(com.facebook.presto.spi.PrestoException) AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray) NotSupportedException(com.facebook.presto.common.NotSupportedException)

Example 2 with AdaptiveLongBigArray

use of com.facebook.presto.common.array.AdaptiveLongBigArray in project presto by prestodb.

the class PagesSpatialIndexSupplier method buildRTree.

private static Flatbush<GeometryWithPosition> buildRTree(AdaptiveLongBigArray addresses, int positionCount, List<List<Block>> channels, int geometryChannel, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, LocalMemoryContext localUserMemoryContext) {
    Operator relateOperator = OperatorFactoryLocal.getInstance().getOperator(Operator.Type.Relate);
    ObjectArrayList<GeometryWithPosition> geometries = new ObjectArrayList<>();
    long recordedSizeInBytes = localUserMemoryContext.getBytes();
    long addedSizeInBytes = 0;
    for (int position = 0; position < positionCount; position++) {
        long pageAddress = addresses.get(position);
        int blockIndex = decodeSliceIndex(pageAddress);
        int blockPosition = decodePosition(pageAddress);
        Block block = channels.get(geometryChannel).get(blockIndex);
        // TODO Consider pushing is-null and is-empty checks into a filter below the join
        if (block.isNull(blockPosition)) {
            continue;
        }
        Slice slice = block.getSlice(blockPosition, 0, block.getSliceLength(blockPosition));
        OGCGeometry ogcGeometry = deserialize(slice);
        verify(ogcGeometry != null);
        if (ogcGeometry.isEmpty()) {
            continue;
        }
        double radius = radiusChannel.map(channel -> DOUBLE.getDouble(channels.get(channel).get(blockIndex), blockPosition)).orElse(0.0);
        if (radius < 0) {
            continue;
        }
        if (!radiusChannel.isPresent()) {
            // If radiusChannel is supplied, this is a distance query, for which our acceleration won't help.
            accelerateGeometry(ogcGeometry, relateOperator);
        }
        int partition = -1;
        if (partitionChannel.isPresent()) {
            Block partitionBlock = channels.get(partitionChannel.get()).get(blockIndex);
            partition = toIntExact(INTEGER.getLong(partitionBlock, blockPosition));
        }
        GeometryWithPosition geometryWithPosition = new GeometryWithPosition(ogcGeometry, partition, position, radius);
        geometries.add(geometryWithPosition);
        addedSizeInBytes += geometryWithPosition.getEstimatedSizeInBytes();
        if (addedSizeInBytes >= MEMORY_USAGE_UPDATE_INCREMENT_BYTES) {
            localUserMemoryContext.setBytes(recordedSizeInBytes + addedSizeInBytes);
            recordedSizeInBytes += addedSizeInBytes;
            addedSizeInBytes = 0;
        }
    }
    return new Flatbush<>(geometries.toArray(new GeometryWithPosition[] {}));
}
Also used : Operator(com.esri.core.geometry.Operator) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) Slice(io.airlift.slice.Slice) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) Supplier(java.util.function.Supplier) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray) Math.toIntExact(java.lang.Math.toIntExact) SyntheticAddress.decodePosition(com.facebook.presto.operator.SyntheticAddress.decodePosition) Type(com.facebook.presto.common.type.Type) Operator(com.esri.core.geometry.Operator) OperatorFactoryLocal(com.esri.core.geometry.OperatorFactoryLocal) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Session(com.facebook.presto.Session) LocalMemoryContext(com.facebook.presto.memory.context.LocalMemoryContext) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush) Rectangle(com.facebook.presto.geospatial.Rectangle) DataSize(io.airlift.units.DataSize) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) EsriGeometrySerde.deserialize(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SyntheticAddress.decodeSliceIndex(com.facebook.presto.operator.SyntheticAddress.decodeSliceIndex) GeometryUtils.accelerateGeometry(com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry) Optional(java.util.Optional) EMPTY_INDEX(com.facebook.presto.operator.PagesSpatialIndex.EMPTY_INDEX) Block(com.facebook.presto.common.block.Block) BYTE(io.airlift.units.DataSize.Unit.BYTE) SpatialPredicate(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialPredicate) GeometryWithPosition(com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) GeometryWithPosition(com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition) Slice(io.airlift.slice.Slice) Block(com.facebook.presto.common.block.Block) Flatbush(com.facebook.presto.geospatial.rtree.Flatbush)

Example 3 with AdaptiveLongBigArray

use of com.facebook.presto.common.array.AdaptiveLongBigArray in project presto by prestodb.

the class TestPositionLinks method addresses.

private static AdaptiveLongBigArray addresses() {
    AdaptiveLongBigArray addresses = new AdaptiveLongBigArray();
    addresses.ensureCapacity(TEST_PAGE.getPositionCount());
    for (int i = 0; i < TEST_PAGE.getPositionCount(); ++i) {
        addresses.set(i, encodeSyntheticAddress(0, i));
    }
    return addresses;
}
Also used : AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray)

Example 4 with AdaptiveLongBigArray

use of com.facebook.presto.common.array.AdaptiveLongBigArray in project presto by prestodb.

the class PagesIndexPageSorter method sort.

@Override
public long[] sort(List<Type> types, List<Page> pages, List<Integer> sortChannels, List<SortOrder> sortOrders, int expectedPositions) {
    PagesIndex pagesIndex = pagesIndexFactory.newPagesIndex(types, expectedPositions);
    pages.forEach(pagesIndex::addPage);
    pagesIndex.sort(sortChannels, sortOrders);
    int positionCount = pagesIndex.getPositionCount();
    AdaptiveLongBigArray valueAddresses = pagesIndex.getValueAddresses();
    long[] result = new long[positionCount];
    for (int i = 0; i < positionCount; i++) {
        result[i] = valueAddresses.get(i);
    }
    return result;
}
Also used : PagesIndex(com.facebook.presto.operator.PagesIndex) AdaptiveLongBigArray(com.facebook.presto.common.array.AdaptiveLongBigArray)

Aggregations

AdaptiveLongBigArray (com.facebook.presto.common.array.AdaptiveLongBigArray)4 Block (com.facebook.presto.common.block.Block)2 Type (com.facebook.presto.common.type.Type)2 Operator (com.esri.core.geometry.Operator)1 OperatorFactoryLocal (com.esri.core.geometry.OperatorFactoryLocal)1 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)1 Session (com.facebook.presto.Session)1 NotSupportedException (com.facebook.presto.common.NotSupportedException)1 SortOrder (com.facebook.presto.common.block.SortOrder)1 DOUBLE (com.facebook.presto.common.type.DoubleType.DOUBLE)1 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)1 GeometryUtils.accelerateGeometry (com.facebook.presto.geospatial.GeometryUtils.accelerateGeometry)1 Rectangle (com.facebook.presto.geospatial.Rectangle)1 Flatbush (com.facebook.presto.geospatial.rtree.Flatbush)1 EsriGeometrySerde.deserialize (com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize)1 LocalMemoryContext (com.facebook.presto.memory.context.LocalMemoryContext)1 PagesIndex (com.facebook.presto.operator.PagesIndex)1 GeometryWithPosition (com.facebook.presto.operator.PagesRTreeIndex.GeometryWithPosition)1 EMPTY_INDEX (com.facebook.presto.operator.PagesSpatialIndex.EMPTY_INDEX)1 SpatialPredicate (com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialPredicate)1