MaxGekk commented on issue #26165: [SPARK-29508][SQL] Implicitly cast strings in datetime arithmetic operations URL: https://github.com/apache/spark/pull/26165#issuecomment-545094021 > Users can simply put the INTERVAL keyword before the string literal ... You are right, users can put it before literals but what about string column. Users have to explicitly cast it, correct? > People may get null result silently and hide the mistake(they may pick a wrong column to add). Yeh, though the same argument is applicable to other implicit cast from strings, for example: ```sql spark-sql> select 2 * '3'; 6.0 ``` Why does Spark implicitly cast `'3'` to a numeric. Maybe an user wants to repeat `'3'` two times, and get `'33'`? Let's consider proposed implicit casts one by one: 1. `select interval '1 month' - <string>`. What else could we subtract from interval besides of another interval. Don't think casting to interval is ambiguous, here. 2. `select timestamp'today' + <string>`. What else could we add to a timestamp or date? Definitely, not another timestamp or date. Maybe we could add a number but what is the number - days, seconds or microseconds? Obviously, a timestamp can be adjusted by an interval. 3. `select date'today' - <string>`. Here, I follow PostgreSQL which cast the string to datetime implicitly: ```sql maxim=# select date'today' - '2019-10-01'; ?column? ---------- 21 (1 row) ```
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
