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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -646,7 +646,7 @@ abstract class CastBase extends UnaryExpression with 
TimeZoneAwareExpression wit
    * NOTE: this modifies `value` in-place, so don't call it on external data.
    */
   private[this] def changePrecision(value: Decimal, decimalType: DecimalType): 
Decimal = {
-    if (value.changePrecision(decimalType.precision, decimalType.scale)) {
+    if (value != null && value.changePrecision(decimalType.precision, 
decimalType.scale)) {

Review comment:
       the null check is only needed for non-ansi mode. Shall we put it there?
   ```
   buildCast[UTF8String](_, s => {
     val d = Decimal.fromString(s)
     if  (d == null) null else changePrecision(d, target)
   })
   ```




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