-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25098][SQL]‘Cast’ will return NULL when input string starts/en… #22089
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
Conversation
…ds with special character(s)
|
Can one of the admins verify this patch? |
| case StringType => | ||
| buildCast[UTF8String](_, utfs => DateTimeUtils.stringToTimestamp(utfs, timeZone).orNull) | ||
| buildCast[UTF8String](_, utfs => DateTimeUtils.stringToTimestamp( | ||
| UTF8String.fromString(utfs.toString.trim), timeZone).orNull) |
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.
why not utfs.trim()?
|
ping @bingbai0912 |
| c.set(Calendar.MILLISECOND, 0) | ||
| checkEvaluation(Cast(Literal("2015-03-18"), DateType), new Date(c.getTimeInMillis)) | ||
| checkEvaluation(Cast(Literal("2015-03-18 "), DateType), new Date(c.getTimeInMillis)) | ||
| checkEvaluation(Cast(Literal(" 2015-03-18"), DateType), new Date(c.getTimeInMillis)) |
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.
SELECT CAST(' 22-OCT-1997' AS TIMESTAMP) FROM dual;
Oracle also trims the leading space.
|
@wangyum Could you please take it over? |
|
Sure, @gatorsmile . |
…ringToDate ## What changes were proposed in this pull request? **Hive** and **Oracle** trim the string when cast `stringToTimestamp` and `stringToDate`. this PR support this feature:   ## How was this patch tested? unit tests Closes apache#22089 Closes apache#22943 from wangyum/SPARK-25098. Authored-by: Yuming Wang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
What changes were proposed in this pull request?
UDF ‘Cast’ will return NULL when input string starts/ends with special character, but hive doesn't.
For examle, we get hour from a string ends with a blank :
hive:
spark-sql:
All of the following UDFs will be affected:
How was this patch tested?
Add test cases