use of io.trino.spi.TrinoException in project trino by trinodb.
the class GeoFunctions method toSphericalGeography.
@Description("Converts a Geometry object to a SphericalGeography object")
@ScalarFunction("to_spherical_geography")
@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME)
public static Slice toSphericalGeography(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
// "every point in input is in range" <=> "the envelope of input is in range"
Envelope envelope = deserializeEnvelope(input);
if (!envelope.isEmpty()) {
checkLatitude(envelope.getYMin());
checkLatitude(envelope.getYMax());
checkLongitude(envelope.getXMin());
checkLongitude(envelope.getXMax());
}
OGCGeometry geometry = deserialize(input);
if (geometry.is3D()) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert 3D geometry to a spherical geography");
}
GeometryCursor cursor = geometry.getEsriGeometryCursor();
while (true) {
com.esri.core.geometry.Geometry subGeometry = cursor.next();
if (subGeometry == null) {
break;
}
if (!GEOMETRY_TYPES_FOR_SPHERICAL_GEOGRAPHY.contains(subGeometry.getType())) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "Cannot convert geometry of this type to spherical geography: " + subGeometry.getType());
}
}
return input;
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class GeoFunctions method geometryFromHadoopShape.
@Description("Returns a Geometry type object from Spatial Framework for Hadoop representation")
@ScalarFunction("geometry_from_hadoop_shape")
@SqlType(GEOMETRY_TYPE_NAME)
public static Slice geometryFromHadoopShape(@SqlType(VARBINARY) Slice input) {
requireNonNull(input, "input is null");
try {
OGCGeometry geometry = OGCGeometry.fromEsriShape(getShapeByteBuffer(input));
String wkt = geometryToWkt(geometry.getEsriGeometry(), getWktExportFlags(input));
return serialize(OGCGeometry.fromText(wkt));
} catch (IndexOutOfBoundsException | UnsupportedOperationException | IllegalArgumentException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "Invalid Hadoop shape", e);
}
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class GeoFunctions method geometryFromText.
private static OGCGeometry geometryFromText(Slice input) {
OGCGeometry geometry;
try {
geometry = OGCGeometry.fromText(input.toStringUtf8());
} catch (IllegalArgumentException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKT: " + input.toStringUtf8(), e);
}
geometry.setSpatialReference(null);
return geometry;
}
use of io.trino.spi.TrinoException in project trino by trinodb.
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 TrinoException(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 TrinoException(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 TrinoException(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));
}
use of io.trino.spi.TrinoException in project trino by trinodb.
the class FileSystemExchangeManager method createExchange.
@Override
public Exchange createExchange(ExchangeContext context, int outputPartitionCount) {
Optional<SecretKey> secretKey = Optional.empty();
if (exchangeEncryptionEnabled) {
try {
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(KEY_BITS);
secretKey = Optional.of(keyGenerator.generateKey());
} catch (NoSuchAlgorithmException e) {
throw new TrinoException(GENERIC_INTERNAL_ERROR, "Failed to generate new secret key: " + e.getMessage(), e);
}
}
FileSystemExchange exchange = new FileSystemExchange(baseDirectory, exchangeStorage, context, outputPartitionCount, secretKey, executor);
exchange.initialize();
return exchange;
}
Aggregations