use of io.trino.spi.type.LongTimeWithTimeZone in project trino by trinodb.
the class VarcharToTimeWithTimeZoneCast method castToLong.
@LiteralParameters({ "x", "p" })
@SqlType("time(p) with time zone")
public static LongTimeWithTimeZone castToLong(@LiteralParameter("p") long precision, ConnectorSession session, @SqlType("varchar(x)") Slice value) {
checkArgument((int) precision > MAX_SHORT_PRECISION && (int) precision <= MAX_PRECISION, "precision out of range");
Matcher matcher = DateTimes.TIME_PATTERN.matcher(trim(value).toStringUtf8());
if (!matcher.matches()) {
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8());
}
try {
long picos = parseTime(matcher) * PICOSECONDS_PER_SECOND + parseFraction((int) precision, matcher, 12);
picos %= PICOSECONDS_PER_DAY;
int offsetMinutes = parseOffset(session, matcher);
return new LongTimeWithTimeZone(picos, offsetMinutes);
} catch (IllegalArgumentException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e);
}
}
Aggregations