Open JamesRTaylor opened 3 years ago
The VarcharToTimestampCast
should catch DateTimeException
and rethrow as PrestoException
with proper error code.
It might be better to just validate the range of values for each field directly. There's an opportunity for producing better error messages.
I'll try to do this one; assigned to myself. Found that it can be reproduced with:
select cast('2020-01-01 24:01:01' as timestamp)
java.time.DateTimeException: Invalid value for HourOfDay (valid values 0 - 23): 24 at java.base/java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311) at java.base/java.time.temporal.ChronoField.checkValidValue(ChronoField.java:717)
And it does report INTERNAL_ERROR/GENERIC_INTERNAL_ERROR (65536) on the UI.
@martint
It might be better to just validate the range of values for each field directly. There's an opportunity for producing better error messages.
The DateTimeException
has very good messages already, so I think we can just leverage them to give good messages out of the original error. Then we can avoid adding much extra logic. E.g.
catch (DateTimeException e) {
//Leverage highly specific error message from the source exception.
throw new PrestoException(INVALID_CAST_ARGUMENT,
String.format("Value cannot be cast to timestamp; %s. ", e.getMessage()), e);
}
Produces a user-error like:
SQL Error [9]: Query failed (#20201115_215031_00010_bqy8y): Value cannot be cast to timestamp; Invalid value for HourOfDay (valid values 0 - 23): 24.
or:
SQL Error [9]: Query failed (#20201115_215055_00011_bqy8y): Value cannot be cast to timestamp; Invalid value for MonthOfYear (valid values 1 - 12): 13.
For these two bad cast values respectively.
select cast('2020-13-01 23:61:01' as timestamp);
select cast('2020-13-01 23:59:01' as timestamp);
Does this look okay to you approach-wise?
@martint - Made a PR with the above fix and some text cases for you to review. Happy to change it if you have any issues. Thanks!
This is still listed as Open, but it looks like it has been fixed. Is that correct?
@rnzucker Thanks for bumping this up - I see the PR is still open ~but I cannot reproduce the behaviour anymore with select cast('2020-01-01 24:01:01' as timestamp)
.~
~Closing. Feel free to re-open if needed.~
EDIT: I apparently misread the issue, it's still classified as an INTERNAL_ERROR. The PR needs to be rebased and should be good to go then.
Okay. I was just looking for issues for my son to start on for his first OSS project (in Java). Hence my question.
Seeing the following exception which ends up being classified as an INTERNAL_ERROR instead of a USER_ERROR: