mgaido91 commented on a change in pull request #21599: [SPARK-26218][SQL] 
Overflow on arithmetic operations returns incorrect result
URL: https://github.com/apache/spark/pull/21599#discussion_r305412766
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
 ##########
 @@ -170,9 +196,27 @@ case class Add(left: Expression, right: Expression) 
extends BinaryArithmetic {
     if (dataType.isInstanceOf[CalendarIntervalType]) {
       
input1.asInstanceOf[CalendarInterval].add(input2.asInstanceOf[CalendarInterval])
     } else {
-      numeric.plus(input1, input2)
+      val result = numeric.plus(input1, input2)
+      if (checkOverflow) {
+        val resSignum = numeric.signum(result)
+        val input1Signum = numeric.signum(input1)
+        val input2Signum = numeric.signum(input2)
+        if (resSignum != -1 && input1Signum == -1 && input2Signum == -1
+          || resSignum != 1 && input1Signum == 1 && input2Signum == 1) {
 
 Review comment:
   because since here we are using `numeric` in order for the code to be 
generic for alla data types, `numeric` exposes `signum` but not comparison 
operators, which are instead available in codegen since the datatypes are 
specified

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