-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
TRY should handle invalid value error in cast VACHAR as TIMESTAMP #11259
Conversation
a7934c8
to
4b5d21b
Compare
.toEpochSecond(); | ||
} | ||
catch (DateTimeException e) { | ||
throw new IllegalArgumentException("Invalid timestamp: " + value, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TrinoException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Is it better to replace another IllegalArgumentException in this method too?
trino/core/trino-main/src/main/java/io/trino/operator/scalar/timestamp/VarcharToTimestampCast.java
Lines 120 to 122 in 102ab2a
if (!matcher.matches()) { | |
throw new IllegalArgumentException("Invalid timestamp: " + value); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please
core/trino-main/src/main/java/io/trino/operator/scalar/timestamp/VarcharToTimestampCast.java
Outdated
Show resolved
Hide resolved
4b5d21b
to
15a4511
Compare
catch (ZoneRulesException e) { | ||
throw new TrinoException(INVALID_CAST_ARGUMENT, "Value cannot be cast to timestamp: " + value, e); | ||
} | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge try
blocks together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged into a single try block.
@@ -70,6 +71,7 @@ public void testExceptions() | |||
assertFunction(createTryExpression("1/0"), INTEGER, null); | |||
assertFunction(createTryExpression("JSON_PARSE('INVALID')"), JSON, null); | |||
assertFunction(createTryExpression("CAST(NULL AS INTEGER)"), INTEGER, null); | |||
assertFunction(createTryExpression("CAST('0000-00-00' AS TIMESTAMP)"), TIMESTAMP_MILLIS, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test with timestamp with time zone
- zero day of month
- invalid tz specifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added cases.
15a4511
to
6d5d136
Compare
Description
Previously (at least in 317),
TRY(CAST(xxxx AS TIMESTAMP)
returnedNULL
for a timestamp that contains an invalid value like0000-00-00
but in the latest Trino, it fails with the following error:Trino's document says:
Therefore, I think TRY should cover this case. This pull request will resurrect the previous behavior which returns
NULL
for invalid values in timestamp.Related issues, pull requests, and links
Documentation
(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
( ) No release notes entries required.
(x) Release notes entries required with the following suggested text: