use of io.trino.spi.type.TimeZoneNotSupportedException in project trino by trinodb.
the class WithTimeZone method shortPrecision.
@LiteralParameters({ "x", "p" })
@SqlType("timestamp(p) with time zone")
public static long shortPrecision(@LiteralParameter("p") long precision, @SqlType("timestamp(p)") long timestamp, @SqlType("varchar(x)") Slice zoneId) {
verify(precision <= 3, "Expected precision <= 3");
TimeZoneKey toTimeZoneKey;
try {
toTimeZoneKey = getTimeZoneKey(zoneId.toStringUtf8());
} catch (TimeZoneNotSupportedException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("'%s' is not a valid time zone", zoneId.toStringUtf8()));
}
DateTimeZone toDateTimeZone = getDateTimeZone(toTimeZoneKey);
return packDateTimeWithZone(UTC.getMillisKeepLocal(toDateTimeZone, scaleEpochMicrosToMillis(timestamp)), toTimeZoneKey);
}
use of io.trino.spi.type.TimeZoneNotSupportedException in project trino by trinodb.
the class TestServer method testInvalidSessionError.
@Test
public void testInvalidSessionError() {
String invalidTimeZone = "this_is_an_invalid_time_zone";
QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(TRINO_HEADERS.requestCatalog(), "catalog").setHeader(TRINO_HEADERS.requestSchema(), "schema").setHeader(TRINO_HEADERS.requestPath(), "path").setHeader(TRINO_HEADERS.requestTimeZone(), invalidTimeZone)).map(JsonResponse::getValue).peek(result -> checkState((result.getError() == null) != (result.getNextUri() == null))).collect(last());
QueryError queryError = queryResults.getError();
assertNotNull(queryError);
TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
assertEquals(queryError.getMessage(), expected.getMessage());
}
use of io.trino.spi.type.TimeZoneNotSupportedException in project trino by trinodb.
the class AtTimeZone method atTimeZone.
@LiteralParameters({ "x", "p" })
@SqlType("time(p) with time zone")
public static LongTimeWithTimeZone atTimeZone(ConnectorSession session, @SqlType("time(p) with time zone") LongTimeWithTimeZone time, @SqlType("varchar(x)") Slice zoneId) {
TimeZoneKey zoneKey;
try {
zoneKey = getTimeZoneKey(zoneId.toStringUtf8());
} catch (TimeZoneNotSupportedException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("'%s' is not a valid time zone", zoneId));
}
int offsetMinutes = getOffsetMinutes(session.getStart(), zoneKey);
long picos = time.getPicoseconds() - (time.getOffsetMinutes() - offsetMinutes) * PICOSECONDS_PER_MINUTE;
return new LongTimeWithTimeZone(floorMod(picos, PICOSECONDS_PER_DAY), offsetMinutes);
}
use of io.trino.spi.type.TimeZoneNotSupportedException in project trino by trinodb.
the class AtTimeZone method atTimeZone.
@LiteralParameters({ "x", "p" })
@SqlType("time(p) with time zone")
public static long atTimeZone(ConnectorSession session, @SqlType("time(p) with time zone") long packedTime, @SqlType("varchar(x)") Slice zoneId) {
TimeZoneKey zoneKey;
try {
zoneKey = getTimeZoneKey(zoneId.toStringUtf8());
} catch (TimeZoneNotSupportedException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("'%s' is not a valid time zone", zoneId));
}
int offsetMinutes = getOffsetMinutes(session.getStart(), zoneKey);
long nanos = unpackTimeNanos(packedTime) - (unpackOffsetMinutes(packedTime) - offsetMinutes) * NANOSECONDS_PER_MINUTE;
return packTimeWithTimeZone(floorMod(nanos, NANOSECONDS_PER_DAY), offsetMinutes);
}
use of io.trino.spi.type.TimeZoneNotSupportedException in project trino by trinodb.
the class WithTimeZone method toLong.
private static LongTimestampWithTimeZone toLong(long epochMicros, int picosOfMicro, Slice zoneId) {
TimeZoneKey toTimeZoneKey;
try {
toTimeZoneKey = getTimeZoneKey(zoneId.toStringUtf8());
} catch (TimeZoneNotSupportedException e) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, format("'%s' is not a valid time zone", zoneId.toStringUtf8()));
}
DateTimeZone toDateTimeZone = getDateTimeZone(toTimeZoneKey);
long epochMillis = scaleEpochMicrosToMillis(epochMicros);
epochMillis = UTC.getMillisKeepLocal(toDateTimeZone, epochMillis);
int picosOfMilli = getMicrosOfMilli(epochMicros) * PICOSECONDS_PER_MICROSECOND + picosOfMicro;
return LongTimestampWithTimeZone.fromEpochMillisAndFraction(epochMillis, picosOfMilli, toTimeZoneKey);
}
Aggregations