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_r304790863
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
 ##########
 @@ -128,17 +128,31 @@ abstract class BinaryArithmetic extends BinaryOperator 
with NullIntolerant {
   def calendarIntervalMethod: String =
     sys.error("BinaryArithmetics must override either calendarIntervalMethod 
or genCode")
 
+  def checkOverflowCode(result: String, op1: String, op2: String): String =
+    sys.error("BinaryArithmetics must override either checkOverflowCode or 
genCode")
+
   override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = 
dataType match {
     case _: DecimalType =>
       defineCodeGen(ctx, ev, (eval1, eval2) => 
s"$eval1.$decimalMethod($eval2)")
     case CalendarIntervalType =>
       defineCodeGen(ctx, ev, (eval1, eval2) => 
s"$eval1.$calendarIntervalMethod($eval2)")
+    // In the following cases, overflow can happen, so we need to check the 
result is valid.
+    // Otherwise we throw an ArithmeticException
 
 Review comment:
   Thanks for your comment @HyukjinKwon . The issue with returning null is 
described in https://github.com/apache/spark/pull/21599#issuecomment-409201709 
(moreover this behavior would be against SQL standard, but that's a minor 
point). 

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