iRakson commented on a change in pull request #26933: [SPARK-30292][SQL]Throw 
Exception when invalid string is cast to numeric type in ANSI mode
URL: https://github.com/apache/spark/pull/26933#discussion_r364108309
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ##########
 @@ -636,7 +644,12 @@ abstract class CastBase extends UnaryExpression with 
TimeZoneAwareExpression wit
         // Please refer to https://github.com/apache/spark/pull/26640
         changePrecision(Decimal(new JavaBigDecimal(s.toString.trim)), target)
       } catch {
-        case _: NumberFormatException => null
+        case _: NumberFormatException =>
+          if (ansiEnabled) {
+            throw new NumberFormatException(s"invalid input syntax for type 
numeric: $s")
 
 Review comment:
   @cloud-fan `NumberFormatException` is thrown due to `new 
JavaBigDecimal(s.toString.trim)`. 
   And this can't be handled in `changePrecision` as its taking a decimal value 
as input. So i think its better to handle this exception here only.

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

Reply via email to