use of io.trino.spi.function.LiteralParameters in project trino by trinodb.
the class FunctionsParserHelper method parseLiteralParameters.
public static Set<String> parseLiteralParameters(Method method) {
LiteralParameters literalParametersAnnotation = method.getAnnotation(LiteralParameters.class);
if (literalParametersAnnotation == null) {
return ImmutableSet.of();
}
Set<String> result = new TreeSet<>(CASE_INSENSITIVE_ORDER);
result.addAll(Arrays.asList(literalParametersAnnotation.value()));
return result;
}
use of io.trino.spi.function.LiteralParameters 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.LiteralParameters 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.LiteralParameters 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);
}
use of io.trino.spi.function.LiteralParameters in project trino by trinodb.
the class TimestampWithTimeZoneToTimeWithTimeZoneCast method longToShort.
@LiteralParameters({ "sourcePrecision", "targetPrecision" })
@SqlType("time(targetPrecision) with time zone")
public static long longToShort(@LiteralParameter("targetPrecision") long targetPrecision, @SqlType("timestamp(sourcePrecision) with time zone") LongTimestampWithTimeZone timestamp) {
// source precision is > 3
// target precision is <= 9
TimeZoneKey zoneKey = getTimeZoneKey(timestamp.getTimeZoneKey());
long epochMillis = getChronology(zoneKey).getZone().convertUTCToLocal(timestamp.getEpochMillis());
// combine epochMillis with picosOfMilli from the timestamp. We compute modulo 24 to avoid overflow when rescaling epocMilli to picoseconds
long picos = rescale(floorMod(epochMillis, MILLISECONDS_PER_DAY), 3, 12) + timestamp.getPicosOfMilli();
picos = round(picos, (int) (12 - targetPrecision));
picos = floorMod(picos, PICOSECONDS_PER_DAY);
long nanos = rescale(picos, 12, 9);
return packTimeWithTimeZone(nanos, DateTimes.getOffsetMinutes(Instant.ofEpochMilli(epochMillis), zoneKey));
}
Aggregations