Search in sources :

Example 46 with SqlNullable

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

the class ArrayAllMatchFunction method allMatchSlice.

@TypeParameter("T")
@TypeParameterSpecialization(name = "T", nativeContainerType = Slice.class)
@SqlType(StandardTypes.BOOLEAN)
@SqlNullable
public static Boolean allMatchSlice(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") SliceToBooleanFunction function) {
    boolean hasNullResult = false;
    int positionCount = arrayBlock.getPositionCount();
    for (int i = 0; i < positionCount; i++) {
        Slice element = null;
        if (!arrayBlock.isNull(i)) {
            element = elementType.getSlice(arrayBlock, i);
        }
        Boolean match = function.apply(element);
        if (FALSE.equals(match)) {
            return false;
        }
        if (match == null) {
            hasNullResult = true;
        }
    }
    if (hasNullResult) {
        return null;
    }
    return true;
}
Also used : Slice(io.airlift.slice.Slice) TypeParameterSpecialization(com.facebook.presto.spi.function.TypeParameterSpecialization) SqlNullable(com.facebook.presto.spi.function.SqlNullable) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Example 47 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable 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 48 with SqlNullable

use of com.facebook.presto.spi.function.SqlNullable 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)

Example 49 with SqlNullable

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

the class GeoFunctions method stY.

@SqlNullable
@Description("Return the Y coordinate of the point")
@ScalarFunction("ST_Y")
@SqlType(DOUBLE)
public static Double stY(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_Y", geometry, EnumSet.of(POINT));
    if (geometry.isEmpty()) {
        return null;
    }
    return ((org.locationtech.jts.geom.Point) geometry).getY();
}
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.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) 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 50 with SqlNullable

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

the class GeoFunctions method stIsClosed.

@SqlNullable
@Description("Returns TRUE if the LineString or Multi-LineString's start and end points are coincident")
@ScalarFunction("ST_IsClosed")
@SqlType(BOOLEAN)
public static Boolean stIsClosed(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
    Geometry geometry = deserialize(input);
    validateType("ST_IsClosed", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING));
    if (geometry instanceof LineString) {
        return ((LineString) geometry).isClosed();
    } else if (geometry instanceof MultiLineString) {
        return ((MultiLineString) geometry).isClosed();
    }
    // This would be handled in validateType, but for completeness.
    throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid type for isClosed: %s", geometry.getGeometryType()));
}
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) MultiLineString(org.locationtech.jts.geom.MultiLineString) 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) PrestoException(com.facebook.presto.spi.PrestoException) 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

SqlNullable (com.facebook.presto.spi.function.SqlNullable)61 SqlType (com.facebook.presto.spi.function.SqlType)61 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)44 Description (com.facebook.presto.spi.function.Description)37 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)29 PrestoException (com.facebook.presto.spi.PrestoException)17 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)15 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)15 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)15 Geometry (org.locationtech.jts.geom.Geometry)15 JsonUtil.createJsonParser (com.facebook.presto.util.JsonUtil.createJsonParser)14 JsonParser (com.fasterxml.jackson.core.JsonParser)14 IOException (java.io.IOException)14 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)9 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)8 JsonCastException (com.facebook.presto.util.JsonCastException)8 Slice (io.airlift.slice.Slice)8 Point (com.esri.core.geometry.Point)7 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)7 TypeParameter (com.facebook.presto.spi.function.TypeParameter)7