cloud-fan commented on a change in pull request #29731:
URL: https://github.com/apache/spark/pull/29731#discussion_r487711537



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -1192,13 +1218,34 @@ abstract class CastBase extends UnaryExpression with 
TimeZoneAwareExpression wit
           } else {
             s"$evNull =true;"
           }
+          val outOfDecimalCode = if (!ansiEnabled) {
+            s"$evNull = true;"
+          } else {
+            s"""throw new ArithmeticException("out of decimal type range: " + 
$c);"""
+          }
           code"""
+            java.math.BigDecimal $tmpBigDecimal = null;
             try {
-              Decimal $tmp = Decimal.apply(new 
java.math.BigDecimal($c.toString().trim()));
-              ${changePrecision(tmp, target, evPrim, evNull, canNullSafeCast)}
+              $tmpBigDecimal = new java.math.BigDecimal($c.toString().trim());
             } catch (java.lang.NumberFormatException e) {
               $handleException
             }
+
+            if ($tmpBigDecimal != null) {

Review comment:
       it's risky to duplicate the code in codegen. How about we create 
`Decimal.fromString` and `Decimal.fromStringANSI`?




----------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to