cloud-fan 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_r364202002
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ##########
 @@ -1133,7 +1156,11 @@ abstract class CastBase extends UnaryExpression with 
TimeZoneAwareExpression wit
               Decimal $tmp = Decimal.apply(new 
java.math.BigDecimal($c.toString().trim()));
               ${changePrecision(tmp, target, evPrim, evNull, canNullSafeCast)}
             } catch (java.lang.NumberFormatException e) {
-              $evNull = true;
+              if ($ansiEnabled) {
 
 Review comment:
   nit: this will generate java code with if-else, we can do better
   ```
   val handleException = if (ansiEnabled) {
     s"throw new NumberFormatException("invalid input syntax for type numeric: 
$c");"
   } else {
     s"$evNull =true;"
   }
   code"""
     ...
     } catch (java.lang.NumberFormatException e) {
       $handleException
     }
   """
   ```

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