Search in sources :

Example 86 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class ArrayIntersectFunction method intersect.

@ScalarFunction("array_intersect")
@Description("Intersects elements of the two given arrays")
@TypeParameter("E")
@SqlType("array(E)")
public static Block intersect(@TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) {
    if (leftArray.getPositionCount() < rightArray.getPositionCount()) {
        Block tempArray = leftArray;
        leftArray = rightArray;
        rightArray = tempArray;
    }
    int rightPositionCount = rightArray.getPositionCount();
    if (rightPositionCount == 0) {
        return rightArray;
    }
    OptimizedTypedSet typedSet = new OptimizedTypedSet(type, rightPositionCount);
    typedSet.union(rightArray);
    typedSet.intersect(leftArray);
    return typedSet.getBlock();
}
Also used : OptimizedTypedSet(com.facebook.presto.operator.aggregation.OptimizedTypedSet) Block(com.facebook.presto.common.block.Block) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) SqlInvokedScalarFunction(com.facebook.presto.spi.function.SqlInvokedScalarFunction) TypeParameter(com.facebook.presto.spi.function.TypeParameter) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 87 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class BingTileFunctions method bingTileChildren.

@Description("Return the children for a Bing tile")
@ScalarFunction("bing_tile_children")
@SqlType("array(" + BingTileType.NAME + ")")
public static Block bingTileChildren(@SqlType(BingTileType.NAME) long input) {
    BingTile tile = BingTile.decode(input);
    try {
        List<BingTile> children = tile.findChildren();
        BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, children.size());
        children.stream().forEach(child -> BIGINT.writeLong(blockBuilder, child.encode()));
        return blockBuilder.build();
    } catch (IllegalArgumentException e) {
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
    }
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) 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 88 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class GeoFunctions method stExteriorRing.

@SqlNullable
@Description("Returns a line string representing the exterior ring of the POLYGON")
@ScalarFunction("ST_ExteriorRing")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stExteriorRing(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_ExteriorRing", geometry, EnumSet.of(POLYGON));
    if (geometry.isEmpty()) {
        return null;
    }
    return serialize(((org.locationtech.jts.geom.Polygon) geometry).getExteriorRing());
}
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) 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 89 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class GeoFunctions method stSymmetricDifference.

@Description("Returns the Geometry value that represents the point set symmetric difference of two Geometries")
@ScalarFunction("ST_SymDifference")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stSymmetricDifference(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return EsriGeometrySerde.serialize(leftGeometry.symDifference(rightGeometry));
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 90 with Description

use of com.facebook.presto.spi.function.Description in project presto by prestodb.

the class GeoFunctions method stEquals.

@SqlNullable
@Description("Returns TRUE if the given geometries represent the same geometry")
@ScalarFunction("ST_Equals")
@SqlType(BOOLEAN)
public static Boolean stEquals(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
    OGCGeometry leftGeometry = EsriGeometrySerde.deserialize(left);
    OGCGeometry rightGeometry = EsriGeometrySerde.deserialize(right);
    verifySameSpatialReference(leftGeometry, rightGeometry);
    return leftGeometry.Equals(rightGeometry);
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) 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)

Aggregations

Description (com.facebook.presto.spi.function.Description)105 SqlType (com.facebook.presto.spi.function.SqlType)103 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)101 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)41 SqlNullable (com.facebook.presto.spi.function.SqlNullable)37 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)20 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)20 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)20 Geometry (org.locationtech.jts.geom.Geometry)20 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)19 PrestoException (com.facebook.presto.spi.PrestoException)18 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)15 Slice (io.airlift.slice.Slice)15 SqlScalarFunction (com.facebook.presto.metadata.SqlScalarFunction)14 Constraint (com.facebook.presto.type.Constraint)14 DecimalOperators.modulusScalarFunction (com.facebook.presto.type.DecimalOperators.modulusScalarFunction)13 Point (com.esri.core.geometry.Point)10 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)7 SliceUtf8.offsetOfCodePoint (io.airlift.slice.SliceUtf8.offsetOfCodePoint)7 Envelope (com.esri.core.geometry.Envelope)6