use of io.trino.spi.function.SqlNullable in project trino by trinodb.
the class UrlFunctions method urlExtractParameter.
@SqlNullable
@Description("Extract query parameter from url")
@ScalarFunction
@LiteralParameters({ "x", "y" })
@SqlType("varchar(x)")
public static Slice urlExtractParameter(@SqlType("varchar(x)") Slice url, @SqlType("varchar(y)") Slice parameterName) {
URI uri = parseUrl(url);
if ((uri == null) || (uri.getRawQuery() == null)) {
return null;
}
String parameter = parameterName.toStringUtf8();
Iterable<String> queryArgs = QUERY_SPLITTER.split(uri.getRawQuery());
for (String queryArg : queryArgs) {
Iterator<String> arg = ARG_SPLITTER.split(queryArg).iterator();
if (arg.next().equals(parameter)) {
if (arg.hasNext()) {
return decodeUrl(arg.next());
}
// first matched key is empty
return Slices.EMPTY_SLICE;
}
}
// no key matched
return null;
}
use of io.trino.spi.function.SqlNullable in project trino by trinodb.
the class GeoFunctions method stEndPoint.
@SqlNullable
@Description("Returns the last point of a LINESTRING geometry as a Point")
@ScalarFunction("ST_EndPoint")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice stEndPoint(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
OGCGeometry geometry = deserialize(input);
validateType("ST_EndPoint", geometry, EnumSet.of(LINE_STRING));
if (geometry.isEmpty()) {
return null;
}
MultiPath lines = (MultiPath) geometry.getEsriGeometry();
SpatialReference reference = geometry.getEsriSpatialReference();
return serialize(createFromEsriGeometry(lines.getPoint(lines.getPointCount() - 1), reference));
}
use of io.trino.spi.function.SqlNullable in project trino by trinodb.
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) {
OGCGeometry geometry = deserialize(input);
if (geometry.isEmpty()) {
return null;
}
GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType());
if (!type.isMultitype()) {
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1);
GEOMETRY.writeSlice(blockBuilder, serialize(geometry));
return blockBuilder.build();
}
OGCGeometryCollection collection = (OGCGeometryCollection) geometry;
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.numGeometries());
for (int i = 0; i < collection.numGeometries(); i++) {
GEOMETRY.writeSlice(blockBuilder, serialize(collection.geometryN(i)));
}
return blockBuilder.build();
}
use of io.trino.spi.function.SqlNullable in project trino by trinodb.
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.trino.spi.function.SqlNullable in project trino by trinodb.
the class GeoFunctions method lineInterpolatePoints.
@SqlNullable
@Description("Returns an array of Points interpolated along a LineString.")
@ScalarFunction("line_interpolate_points")
@SqlType("array(" + GEOMETRY_TYPE_NAME + ")")
public static Block lineInterpolatePoints(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(StandardTypes.DOUBLE) double fractionStep) {
OGCGeometry geometry = deserialize(input);
if (geometry.isEmpty()) {
return null;
}
List<Point> interpolatedPoints = interpolatePoints(geometry, fractionStep, true);
BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, interpolatedPoints.size());
for (Point point : interpolatedPoints) {
GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(point, null)));
}
return blockBuilder.build();
}
Aggregations