Description
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:
```
hive> SELECT CAST(' 2018-08-13' AS DATE);//starts with a blank
OK
2018-08-13
hive> SELECT HOUR('2018-08-13 17:20:07 );//ends with a blank
OK
17
```
spark-sql:
```
spark-sql> SELECT CAST(' 2018-08-13' AS DATE);//starts with a blank
NULL
spark-sql> SELECT HOUR('2018-08-13 17:20:07 );//ends with a blank
NULL
```
All of the following UDFs will be affected:
```
year
month
day
hour
minute
second
date_add
date_sub
```
Attachments
Issue Links
- relates to
-
SPARK-28023 Trim the string when cast string type to other types
- Resolved
-
SPARK-30000 Trim the string when cast string type to decimals
- Resolved
- links to