Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,15 @@ public static long currentTime(SqlFunctionProperties properties)
// of TIME WITH TIME ZONE
millis -= valueToSessionTimeZoneOffsetDiff(properties.getSessionStartTime(), getDateTimeZone(properties.getTimeZoneKey()));
}
return packDateTimeWithZone(millis, properties.getTimeZoneKey());
try {
return packDateTimeWithZone(millis, properties.getTimeZoneKey());
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

@Description("current time without time zone")
Expand Down Expand Up @@ -147,7 +155,15 @@ public static Slice currentTimeZone(SqlFunctionProperties properties)
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long currentTimestamp(SqlFunctionProperties properties)
{
return packDateTimeWithZone(properties.getSessionStartTime(), properties.getTimeZoneKey());
try {
return packDateTimeWithZone(properties.getSessionStartTime(), properties.getTimeZoneKey());
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

@Description("current timestamp without time zone")
Expand Down Expand Up @@ -183,7 +199,16 @@ public static long fromUnixTime(@SqlType(StandardTypes.DOUBLE) double unixTime,
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
return packDateTimeWithZone(Math.round(unixTime * 1000), timeZoneKey);

try {
return packDateTimeWithZone(Math.round(unixTime * 1000), timeZoneKey);
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

@ScalarFunction("from_unixtime")
Expand Down Expand Up @@ -268,7 +293,15 @@ public static long fromISO8601Timestamp(SqlFunctionProperties properties, @SqlTy
DateTimeFormatter formatter = ISODateTimeFormat.dateTimeParser()
.withChronology(getChronology(properties.getTimeZoneKey()))
.withOffsetParsed();
return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8()));
try {
return packDateTimeWithZone(parseDateTimeHelper(formatter, iso8601DateTime.toStringUtf8()));
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

@ScalarFunction("from_iso8601_date")
Expand Down Expand Up @@ -304,7 +337,15 @@ public static long timeAtTimeZone(SqlFunctionProperties properties, @SqlType(Sta
@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE)
public static long timestampAtTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIME_ZONE) long timestampWithTimeZone, @SqlType("varchar(x)") Slice zoneId)
{
return packDateTimeWithZone(unpackMillisUtc(timestampWithTimeZone), zoneId.toStringUtf8());
try {
return packDateTimeWithZone(unpackMillisUtc(timestampWithTimeZone), zoneId.toStringUtf8());
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

@ScalarFunction(value = "at_timezone", visibility = HIDDEN)
Expand All @@ -313,7 +354,15 @@ public static long timestampAtTimeZone(@SqlType(StandardTypes.TIMESTAMP_WITH_TIM
{
checkCondition((zoneOffset % 60_000L) == 0L, INVALID_FUNCTION_ARGUMENT, "Invalid time zone offset interval: interval contains seconds");
long zoneOffsetMinutes = zoneOffset / 60_000L;
return packDateTimeWithZone(unpackMillisUtc(timestampWithTimeZone), getTimeZoneKeyForOffset(zoneOffsetMinutes));
try {
return packDateTimeWithZone(unpackMillisUtc(timestampWithTimeZone), getTimeZoneKeyForOffset(zoneOffsetMinutes));
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

@Description("truncate to the specified precision in the session timezone")
Expand Down Expand Up @@ -581,6 +630,9 @@ public static long parseDatetime(SqlFunctionProperties properties, @SqlType("var
.withLocale(properties.getSessionLocale()),
datetime.toStringUtf8()));
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e);
}
Expand Down Expand Up @@ -1384,7 +1436,15 @@ private static long timeAtTimeZone(SqlFunctionProperties properties, long timeWi
localMillis += TimeUnit.DAYS.toMillis(1);
}

return packDateTimeWithZone(millis, timeZoneKey);
try {
return packDateTimeWithZone(millis, timeZoneKey);
}
catch (NotSupportedException | TimeZoneNotSupportedException e) {
throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);
}
}

// HACK WARNING!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,8 @@ public void testNotSupportedTimeZone()
{
String sql = "FROM_UNIXTIME(a.column1, 'yyyy-mm-dd') FROM (VALUES (1)) a (column1)";
assertNotSupported(sql, "Time zone not supported: yyyy-mm-dd");

sql = "FROM_UNIXTIME(a.column1) AT TIME ZONE 'PDT','yyyy-MM-dd HH:mm:ss' FROM (VALUES (1)) a (column1)";
assertNotSupported(sql, "Time zone not supported: PDT");
}
}