GitHub user dilipbiswal opened a pull request: https://github.com/apache/spark/pull/13368
SPARK-15557] expression ((cast(99 as decimal) + '3') * '2.3' ) return NULL In this case, the result type of the expression becomes DECIMAL(38, 36) as we promote the individual string literals to DECIMAL(38, 18) when we handle string promotions for `BinaryArthmaticExpression`. I think we need to cast the string literals to Double type instead. I looked at the history and found that this was changed to use decimal instead of double to avoid potential loss of precision when we cast decimal to double. To double check i ran the query against hive, mysql. This query returns non NULL result for both the databases and both promote the expression to use double. Here is the output. - Hive ```SQL hive> create table l2 as select (cast(99 as decimal(19,6)) + '2') from l1; OK hive> describe l2; OK _c0 double ``` - MySQL ```SQL mysql> create table foo2 as select (cast(99 as decimal(19,6)) + '2') from test; Query OK, 1 row affected (0.01 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> describe foo2; +-----------------------------------+--------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------------------------+--------+------+-----+---------+-------+ | (cast(99 as decimal(19,6)) + '2') | double | NO | | 0 | | +-----------------------------------+--------+------+-----+---------+-------+ ``` ## How was this patch tested? Added a new test in SQLQuerySuite You can merge this pull request into a Git repository by running: $ git pull https://github.com/dilipbiswal/spark spark-15557 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/13368.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #13368 ---- commit 46f34955cd076c376b43bb262be1cff9754c8285 Author: Dilip Biswal <dbis...@us.ibm.com> Date: 2016-05-27T22:35:37Z SPARK-15557] expression ((cast(99 as decimal) + '3') * '2.3' ) return null ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org