Yuming Wang created SPARK-28348:
-----------------------------------
Summary: Avoid cast twice for decimal type
Key: SPARK-28348
URL: https://issues.apache.org/jira/browse/SPARK-28348
Project: Spark
Issue Type: Bug
Components: SQL
Affects Versions: 2.3.3
Reporter: Yuming Wang
Spark 2.1:
{code:scala}
scala> sql("select cast(cast(-34338492.215397047 as decimal(38, 10)) *
cast(-34338492.215397047 as decimal(38, 10)) as decimal(38, 18))").show(false);
+-------------------------------------------------------------------------------------------------------------------+
|CAST((CAST(-34338492.215397047 AS DECIMAL(38,10)) * CAST(-34338492.215397047
AS DECIMAL(38,10))) AS DECIMAL(38,18))|
+-------------------------------------------------------------------------------------------------------------------+
|1179132047626883.596862135856320209
|
+-------------------------------------------------------------------------------------------------------------------+
{code}
Spark 2.3:
{code:scala}
scala> sql("select cast(cast(-34338492.215397047 as decimal(38, 10)) *
cast(-34338492.215397047 as decimal(38, 10)) as decimal(38, 18))").show(false);
+-------------------------------------------------------------------------------------------------------------------+
|CAST((CAST(-34338492.215397047 AS DECIMAL(38,10)) * CAST(-34338492.215397047
AS DECIMAL(38,10))) AS DECIMAL(38,18))|
+-------------------------------------------------------------------------------------------------------------------+
|1179132047626883.596862000000000000
|
+-------------------------------------------------------------------------------------------------------------------+
{code}
I think we do not need to cast result to {{decimal(38, 6)}} and then cast
result to {{decimal(38, 18)}} for this case.
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]