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;
}
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());
}
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);
}
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();
}
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()));
}
Aggregations