use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
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) {
OGCGeometry geometry = deserialize(input);
validateType("ST_Y", geometry, EnumSet.of(POINT));
if (geometry.isEmpty()) {
return null;
}
return ((OGCPoint) geometry).Y();
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class GeoFunctions method stNumInteriorRings.
@SqlNullable
@Description("Returns the cardinality of the collection of interior rings of a polygon")
@ScalarFunction("ST_NumInteriorRing")
@SqlType(BIGINT)
public static Long stNumInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = deserialize(input);
validateType("ST_NumInteriorRing", geometry, EnumSet.of(POLYGON));
if (geometry.isEmpty()) {
return null;
}
return Long.valueOf(((OGCPolygon) geometry).numInteriorRing());
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class GeoFunctions method stIntersects.
@SqlNullable
@Description("Returns TRUE if the Geometries spatially intersect in 2D - (share any portion of space) and FALSE if they don't (they are Disjoint)")
@ScalarFunction("ST_Intersects")
@SqlType(BOOLEAN)
public static Boolean stIntersects(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) {
if (!envelopes(left, right, Envelope::intersect)) {
return false;
}
OGCGeometry leftGeometry = deserialize(left);
OGCGeometry rightGeometry = deserialize(right);
verifySameSpatialReference(leftGeometry, rightGeometry);
return leftGeometry.intersects(rightGeometry);
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class GeoFunctions method stLineString.
@Description("Returns a LineString from an array of points")
@ScalarFunction("ST_LineString")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stLineString(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) {
MultiPath multipath = new Polyline();
OGCPoint previousPoint = null;
for (int i = 0; i < input.getPositionCount(); i++) {
Slice slice = GEOMETRY.getSlice(input, i);
if (slice.getInput().available() == 0) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: null point at index %s", i + 1));
}
OGCGeometry geometry = deserialize(slice);
if (!(geometry instanceof OGCPoint)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("ST_LineString takes only an array of valid points, %s was passed", geometry.geometryType()));
}
OGCPoint point = (OGCPoint) geometry;
if (point.isEmpty()) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: empty point at index %s", i + 1));
}
if (previousPoint == null) {
multipath.startPath(point.X(), point.Y());
} else {
if (point.Equals(previousPoint)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_LineString: consecutive duplicate points at index %s", i + 1));
}
multipath.lineTo(point.X(), point.Y());
}
previousPoint = point;
}
OGCLineString linestring = new OGCLineString(multipath, 0, null);
return serialize(linestring);
}
use of io.prestosql.spi.function.ScalarFunction in project hetu-core by openlookeng.
the class GeoFunctions method stMultiPoint.
@SqlNullable
@Description("Returns a multi-point geometry formed from input points")
@ScalarFunction("ST_MultiPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) {
MultiPoint multipoint = new MultiPoint();
for (int i = 0; i < input.getPositionCount(); i++) {
if (input.isNull(i)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: null at index %s", i + 1));
}
Slice slice = GEOMETRY.getSlice(input, i);
OGCGeometry geometry = deserialize(slice);
if (!(geometry instanceof OGCPoint)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: geometry is not a point: %s at index %s", geometry.geometryType(), i + 1));
}
OGCPoint point = (OGCPoint) geometry;
if (point.isEmpty()) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: empty point at index %s", i + 1));
}
multipoint.add(point.X(), point.Y());
}
if (multipoint.getPointCount() == 0) {
return null;
}
return serialize(createFromEsriGeometry(multipoint, null, true));
}
Aggregations