use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.
the class JsonOperators method castToBigint.
@ScalarOperator(CAST)
@SqlNullable
@SqlType(BIGINT)
public static Long castToBigint(@SqlType(JSON) Slice json) {
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Long result = currentTokenAsBigint(parser);
// check no trailing token
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to BIGINT");
return result;
} catch (IOException | JsonCastException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, String.format("Cannot cast '%s' to %s", json.toStringUtf8(), BIGINT), e);
}
}
use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.
the class JsonOperators method castToTinyint.
@ScalarOperator(CAST)
@SqlNullable
@SqlType(TINYINT)
public static Long castToTinyint(@SqlType(JSON) Slice json) {
try (JsonParser parser = createJsonParser(JSON_FACTORY, json)) {
parser.nextToken();
Long result = currentTokenAsTinyint(parser);
// check no trailing token
checkCondition(parser.nextToken() == null, INVALID_CAST_ARGUMENT, "Cannot cast input json to TINYINT");
return result;
} catch (PrestoException e) {
if (e.getErrorCode().equals(NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode())) {
throw new PrestoException(INVALID_CAST_ARGUMENT, String.format("Cannot cast '%s' to %s", json.toStringUtf8(), INTEGER), e.getCause());
}
throw e;
} catch (IllegalArgumentException | IOException | JsonCastException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, String.format("Cannot cast '%s' to %s", json.toStringUtf8(), TINYINT), e);
}
}
use of io.prestosql.spi.function.SqlNullable in project hetu-core by openlookeng.
the class GeoFunctions method invalidReason.
@Description("Returns the reason for why the input geometry is not valid. Returns null if the input is valid.")
@ScalarFunction("geometry_invalid_reason")
@SqlType(VARCHAR)
@SqlNullable
public static Slice invalidReason(@SqlType(GEOMETRY_TYPE_NAME) Slice input) {
GeometryCursor cursor = deserialize(input).getEsriGeometryCursor();
NonSimpleResult result = new NonSimpleResult();
while (true) {
com.esri.core.geometry.Geometry geometry = cursor.next();
if (geometry == null) {
return null;
}
if (!OperatorSimplifyOGC.local().isSimpleOGC(geometry, null, true, result, null)) {
String reasonText = NON_SIMPLE_REASONS.getOrDefault(result.m_reason, result.m_reason.name());
if (!(geometry instanceof MultiVertexGeometry)) {
return utf8Slice(reasonText);
}
MultiVertexGeometry multiVertexGeometry = (MultiVertexGeometry) geometry;
if (result.m_vertexIndex1 >= 0 && result.m_vertexIndex2 >= 0) {
Point point1 = multiVertexGeometry.getPoint(result.m_vertexIndex1);
Point point2 = multiVertexGeometry.getPoint(result.m_vertexIndex2);
return utf8Slice(format("%s at or near (%s %s) and (%s %s)", reasonText, point1.getX(), point1.getY(), point2.getX(), point2.getY()));
}
if (result.m_vertexIndex1 >= 0) {
Point point = multiVertexGeometry.getPoint(result.m_vertexIndex1);
return utf8Slice(format("%s at or near (%s %s)", reasonText, point.getX(), point.getY()));
}
return utf8Slice(reasonText);
}
}
}
use of io.prestosql.spi.function.SqlNullable 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.SqlNullable 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());
}
Aggregations