Skip to content

Commit

Permalink
Fix cast time w/ tz exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
everypp authored Jan 10, 2024
1 parent 5fbf6b0 commit c809c1f
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ private VarcharToTimeWithTimeZoneCast() {}
@SqlType("time(p) with time zone")
public static long castToShort(@LiteralParameter("p") long precision, ConnectorSession session, @SqlType("varchar(x)") Slice value)
{
checkArgument((int) precision <= MAX_SHORT_PRECISION, "precision must be less than max short timestamp precision");
checkArgument((int) precision <= MAX_SHORT_PRECISION, "precision must be less than max short time with time zone precision");

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());
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to time with time zone: " + value.toStringUtf8());
}

try {
Expand All @@ -67,7 +67,7 @@ public static long castToShort(@LiteralParameter("p") long precision, ConnectorS
return packTimeWithTimeZone(nanos, offsetMinutes);
}
catch (IllegalArgumentException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e);
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to time with time zone: " + value.toStringUtf8(), e);
}
}

Expand All @@ -79,7 +79,7 @@ public static LongTimeWithTimeZone castToLong(@LiteralParameter("p") long precis

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());
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to time with time zone: " + value.toStringUtf8());
}

try {
Expand All @@ -91,7 +91,7 @@ public static LongTimeWithTimeZone castToLong(@LiteralParameter("p") long precis
return new LongTimeWithTimeZone(picos, offsetMinutes);
}
catch (IllegalArgumentException e) {
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value.toStringUtf8(), e);
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to time with time zone: " + value.toStringUtf8(), e);
}
}

Expand Down

0 comments on commit c809c1f

Please sign in to comment.