anchovYu opened a new pull request, #36241:
URL: https://github.com/apache/spark/pull/36241
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section
is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster
reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class
hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other
DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
Improve the error messages for cast failures in ANSI.
As mentioned in https://issues.apache.org/jira/browse/SPARK-38929, this PR
targets two cast-to types: numeric types and date types.
* For numeric(`int`, `smallint`, `double`, `float`, `decimal` ..) types, it
embeds the cast-to types in the error message. For example,
```
Invalid `int` literal: '1.0'. To return NULL instead, use 'try_cast'. If
necessary set %s to false to bypass this error.
```
It uses the `toSQLId` and `toSQLValue` to wrap the corresponding types and
literals.
* For date types, it does similarly as above. For example,
```
Invalid `timestamp` literal: 'a'. To return NULL instead, use 'try_cast'. If
necessary set spark.sql.ansi.enabled to false to bypass this error.
```
### Why are the changes needed?
To improve the error message in general.
### Does this PR introduce _any_ user-facing change?
It changes the error messages.
### How was this patch tested?
The related unit tests are updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]