[ 
https://issues.apache.org/jira/browse/SPARK-28348?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16882773#comment-16882773
 ] 

Marco Gaido commented on SPARK-28348:
-------------------------------------

No, I don't think that's a good idea. Setting the result type to {{decimal(p3, 
s3)}} could cause the overflow issues for which 
https://issues.apache.org/jira/browse/SPARK-22036 has been done. On the other 
side, avoiding the cast would change the result type. So I don't see a good way 
to change this.

> 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
>            Priority: Major
>
> 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]

Reply via email to