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());
}
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());
}
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));
}
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);
}
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);
}
Aggregations