Search in sources :

Example 66 with BlockBuilder

use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.

the class GeoFunctions method stGeometries.

@SqlNullable
@Description("Returns an array of geometries in the specified collection")
@ScalarFunction("ST_Geometries")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    GeometryType type = GeometryType.getForJtsGeometryType(geometry.getGeometryType());
    if (!type.isMultitype()) {
        BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1);
        GEOMETRY.writeSlice(blockBuilder, serialize(geometry));
        return blockBuilder.build();
    }
    GeometryCollection collection = (GeometryCollection) geometry;
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.getNumGeometries());
    for (int i = 0; i < collection.getNumGeometries(); i++) {
        GEOMETRY.writeSlice(blockBuilder, serialize(collection.getGeometryN(i)));
    }
    return blockBuilder.build();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) GeometryType(com.facebook.presto.geospatial.GeometryType) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 67 with BlockBuilder

use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.

the class GeoFunctions method flattenGeometryCollections.

@Description("Recursively flattens GeometryCollections")
@ScalarFunction("flatten_geometry_collections")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block flattenGeometryCollections(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    OGCGeometry geometry = EsriGeometrySerde.deserialize(input);
    List<OGCGeometry> components = Streams.stream(flattenCollection(geometry)).collect(toImmutableList());
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, components.size());
    for (OGCGeometry component : components) {
        GEOMETRY.writeSlice(blockBuilder, EsriGeometrySerde.serialize(component));
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 68 with BlockBuilder

use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.

the class GeoFunctions method stInteriorRings.

@SqlNullable
@Description("Returns an array of interior rings of a polygon")
@ScalarFunction("ST_InteriorRings")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_InteriorRings", geometry, EnumSet.of(POLYGON));
    if (geometry.isEmpty()) {
        return null;
    }
    org.locationtech.jts.geom.Polygon polygon = (org.locationtech.jts.geom.Polygon) geometry;
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, polygon.getNumInteriorRing());
    for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        GEOMETRY.writeSlice(blockBuilder, serialize((LineString) polygon.getInteriorRingN(i)));
    }
    return blockBuilder.build();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryUtils.createJtsEmptyLineString(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyLineString) GeometryUtils.createJtsLineString(com.facebook.presto.geospatial.GeometryUtils.createJtsLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) OGCLineString(com.esri.core.geometry.ogc.OGCLineString) LineString(org.locationtech.jts.geom.LineString) GeometryUtils.createJtsEmptyPolygon(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPolygon) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 69 with BlockBuilder

use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.

the class GeoFunctions method stEnvelopeAsPts.

@SqlNullable
@Description("Returns the lower left and upper right corners of bounding rectangular polygon of a Geometry")
@ScalarFunction("ST_EnvelopeAsPts")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block stEnvelopeAsPts(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return null;
    }
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2);
    org.locationtech.jts.geom.Point lowerLeftCorner = createJtsPoint(envelope.getXMin(), envelope.getYMin());
    org.locationtech.jts.geom.Point upperRightCorner = createJtsPoint(envelope.getXMax(), envelope.getYMax());
    GEOMETRY.writeSlice(blockBuilder, serialize(lowerLeftCorner));
    GEOMETRY.writeSlice(blockBuilder, serialize(upperRightCorner));
    return blockBuilder.build();
}
Also used : EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) Envelope(com.esri.core.geometry.Envelope) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 70 with BlockBuilder

use of com.facebook.presto.common.block.BlockBuilder in project presto by prestodb.

the class BingTileFunctions method geometryToBingTiles.

@Description("Given a geometry and a zoom level, returns the minimum set of Bing tiles of that zoom level that fully covers that geometry")
@ScalarFunction("geometry_to_bing_tiles")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block geometryToBingTiles(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.INTEGER) long zoomLevelInput) {
    Envelope envelope = deserializeEnvelope(input);
    if (envelope.isEmpty()) {
        return EMPTY_TILE_ARRAY;
    }
    int zoomLevel = toIntExact(zoomLevelInput);
    GeometrySerializationType type = deserializeType(input);
    List<BingTile> covering;
    if (type == GeometrySerializationType.POINT || type == GeometrySerializationType.ENVELOPE) {
        covering = findMinimalTileCovering(envelope, zoomLevel);
    } else {
        OGCGeometry ogcGeometry = deserialize(input);
        if (isPointOrRectangle(ogcGeometry, envelope)) {
            covering = findMinimalTileCovering(envelope, zoomLevel);
        } else {
            covering = findMinimalTileCovering(ogcGeometry, zoomLevel);
        }
    }
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, covering.size());
    for (BingTile tile : covering) {
        BIGINT.writeLong(blockBuilder, tile.encode());
    }
    return blockBuilder.build();
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) GeometrySerializationType(com.facebook.presto.geospatial.serde.GeometrySerializationType) EsriGeometrySerde.deserializeEnvelope(com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope) BingTileUtils.tileToEnvelope(com.facebook.presto.plugin.geospatial.BingTileUtils.tileToEnvelope) Envelope(com.esri.core.geometry.Envelope) GeometryUtils.disjoint(com.facebook.presto.geospatial.GeometryUtils.disjoint) Point(com.esri.core.geometry.Point) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

BlockBuilder (com.facebook.presto.common.block.BlockBuilder)493 Block (com.facebook.presto.common.block.Block)124 Test (org.testng.annotations.Test)106 Slice (io.airlift.slice.Slice)85 Type (com.facebook.presto.common.type.Type)76 Page (com.facebook.presto.common.Page)49 SqlType (com.facebook.presto.spi.function.SqlType)46 ArrayType (com.facebook.presto.common.type.ArrayType)44 MapType (com.facebook.presto.common.type.MapType)32 RowType (com.facebook.presto.common.type.RowType)28 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)26 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)22 PrestoException (com.facebook.presto.spi.PrestoException)22 PageBuilder (com.facebook.presto.common.PageBuilder)21 StructuralTestUtil.appendToBlockBuilder (com.facebook.presto.util.StructuralTestUtil.appendToBlockBuilder)21 Map (java.util.Map)21 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)20 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)19 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)18 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)18