Search in sources :

Example 31 with SqlType

use of io.trino.spi.function.SqlType in project trino by trinodb.

the class TimeToTimestampWithTimeZoneCast method castToLong.

@LiteralParameters({ "sourcePrecision", "targetPrecision" })
@SqlType("timestamp(targetPrecision) with time zone")
public static LongTimestampWithTimeZone castToLong(@LiteralParameter("sourcePrecision") long sourcePrecision, @LiteralParameter("targetPrecision") long targetPrecision, ConnectorSession session, @SqlType("time(sourcePrecision)") long time) {
    ZoneId zoneId = session.getTimeZoneKey().getZoneId();
    long epochSeconds = getEpochSeconds(session, time, zoneId);
    long picoFraction = getPicoFraction(sourcePrecision, targetPrecision, time);
    long epochMillis = computeEpochMillis(session, zoneId, epochSeconds, picoFraction);
    int picosOfMilli = (int) (picoFraction % PICOSECONDS_PER_MILLISECOND);
    return LongTimestampWithTimeZone.fromEpochMillisAndFraction(epochMillis, picosOfMilli, session.getTimeZoneKey().getKey());
}
Also used : ZoneId(java.time.ZoneId) LiteralParameters(io.trino.spi.function.LiteralParameters) SqlType(io.trino.spi.function.SqlType)

Example 32 with SqlType

use of io.trino.spi.function.SqlType in project trino by trinodb.

the class TimeToTimestampWithTimeZoneCast method castToShort.

@LiteralParameters({ "sourcePrecision", "targetPrecision" })
@SqlType("timestamp(targetPrecision) with time zone")
public static long castToShort(@LiteralParameter("sourcePrecision") long sourcePrecision, @LiteralParameter("targetPrecision") long targetPrecision, ConnectorSession session, @SqlType("time(sourcePrecision)") long time) {
    ZoneId zoneId = session.getTimeZoneKey().getZoneId();
    long epochSeconds = getEpochSeconds(session, time, zoneId);
    long picoFraction = getPicoFraction(sourcePrecision, targetPrecision, time);
    long epochMillis = computeEpochMillis(session, zoneId, epochSeconds, picoFraction);
    return packDateTimeWithZone(epochMillis, session.getTimeZoneKey());
}
Also used : ZoneId(java.time.ZoneId) LiteralParameters(io.trino.spi.function.LiteralParameters) SqlType(io.trino.spi.function.SqlType)

Example 33 with SqlType

use of io.trino.spi.function.SqlType in project trino by trinodb.

the class ToIso8601 method toIso8601.

@LiteralParameters({ "p", "n" })
@SqlType("varchar(n)")
@Constraint(variable = "n", expression = RESULT_LENGTH)
public static Slice toIso8601(@LiteralParameter("p") long precision, @SqlType("timestamp(p) with time zone") long packedEpochMillis) {
    long epochMillis = unpackMillisUtc(packedEpochMillis);
    ZoneId zoneId = unpackZoneKey(packedEpochMillis).getZoneId();
    return utf8Slice(format((int) precision, epochMillis, 0, zoneId));
}
Also used : ZoneId(java.time.ZoneId) LiteralParameters(io.trino.spi.function.LiteralParameters) Constraint(io.trino.type.Constraint) SqlType(io.trino.spi.function.SqlType)

Example 34 with SqlType

use of io.trino.spi.function.SqlType in project trino by trinodb.

the class TimestampWithTimeZoneToDateCast method cast.

@LiteralParameters("p")
@SqlType(StandardTypes.DATE)
public static long cast(@SqlType("timestamp(p) with time zone") long timestamp) {
    long epochMillis = unpackMillisUtc(timestamp);
    TimeZoneKey zoneKey = unpackZoneKey(timestamp);
    return toDate(epochMillis, zoneKey);
}
Also used : TimeZoneKey.getTimeZoneKey(io.trino.spi.type.TimeZoneKey.getTimeZoneKey) TimeZoneKey(io.trino.spi.type.TimeZoneKey) LiteralParameters(io.trino.spi.function.LiteralParameters) SqlType(io.trino.spi.function.SqlType)

Example 35 with SqlType

use of io.trino.spi.function.SqlType in project trino by trinodb.

the class TimestampWithTimeZoneToTimeCast method cast.

@LiteralParameters({ "sourcePrecision", "targetPrecision" })
@SqlType("time(targetPrecision)")
public static long cast(@LiteralParameter("targetPrecision") long targetPrecision, @SqlType("timestamp(sourcePrecision) with time zone") long packedEpochMillis) {
    long epochMillis = unpackMillisUtc(packedEpochMillis);
    ZoneId zoneId = unpackZoneKey(packedEpochMillis).getZoneId();
    return convert(targetPrecision, epochMillis, 0, zoneId);
}
Also used : ZoneId(java.time.ZoneId) LiteralParameters(io.trino.spi.function.LiteralParameters) SqlType(io.trino.spi.function.SqlType)

Aggregations

SqlType (io.trino.spi.function.SqlType)176 ScalarFunction (io.trino.spi.function.ScalarFunction)107 Description (io.trino.spi.function.Description)90 LiteralParameters (io.trino.spi.function.LiteralParameters)60 SqlNullable (io.trino.spi.function.SqlNullable)56 BlockBuilder (io.trino.spi.block.BlockBuilder)52 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)46 TrinoException (io.trino.spi.TrinoException)37 Constraint (io.trino.type.Constraint)23 Slice (io.airlift.slice.Slice)22 TypeParameter (io.trino.spi.function.TypeParameter)21 Point (com.esri.core.geometry.Point)17 OGCPoint (com.esri.core.geometry.ogc.OGCPoint)17 MultiPoint (com.esri.core.geometry.MultiPoint)15 JsonParser (com.fasterxml.jackson.core.JsonParser)14 JsonUtil.createJsonParser (io.trino.util.JsonUtil.createJsonParser)14 IOException (java.io.IOException)14 ScalarOperator (io.trino.spi.function.ScalarOperator)13 SliceUtf8.lengthOfCodePoint (io.airlift.slice.SliceUtf8.lengthOfCodePoint)11 Matcher (io.airlift.joni.Matcher)9