Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cast time tz exception message #20306

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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 @@ -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
Loading