luluorta commented on a change in pull request #29882:
URL: https://github.com/apache/spark/pull/29882#discussion_r514078345



##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala
##########
@@ -500,4 +524,53 @@ class ArithmeticExpressionSuite extends SparkFunSuite with 
ExpressionEvalHelper
       checkEvaluation(e6, 0.toByte)
     }
   }
+
+  private def testDecimalAndLongType(testFunc: (Int => Any) => Unit): Unit = {
+    testFunc(_.toLong)
+    testFunc(Decimal(_))
+  }
+
+  test("SPARK-33008: division by zero on divide-like operations returns 
incorrect result") {
+    withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
+      testDecimalAndDoubleType { convert =>
+        val one = Literal(convert(1))
+        val zero = Literal(convert(0))
+        checkEvaluation(Divide(Literal.create(null, one.dataType), zero), null)
+        checkEvaluation(Divide(one, Literal.create(null, zero.dataType)), null)
+        checkExceptionInExpression[ArithmeticException](Divide(one, zero), 
"divide by zero")
+      }
+
+      testDecimalAndLongType { convert =>
+        val one = Literal(convert(1))
+        val zero = Literal(convert(0))
+        checkEvaluation(IntegralDivide(Literal.create(null, one.dataType), 
zero), null)
+        checkEvaluation(IntegralDivide(one, Literal.create(null, 
zero.dataType)), null)
+        checkExceptionInExpression[ArithmeticException](
+          IntegralDivide(one, zero), "divide by zero")
+      }
+
+      testNumericDataTypes { convert =>
+        val one = Literal(convert(1))
+        val zero = Literal(convert(0))
+        checkEvaluation(Remainder(Literal.create(null, one.dataType), zero), 
null)
+        checkEvaluation(Remainder(one, Literal.create(null, zero.dataType)), 
null)
+        checkExceptionInExpression[ArithmeticException](Remainder(one, zero), 
"divide by zero")
+
+        checkEvaluation(Pmod(Literal.create(null, one.dataType), zero), null)
+        checkEvaluation(Pmod(one, Literal.create(null, zero.dataType)), null)
+        checkExceptionInExpression[ArithmeticException](Pmod(one, zero), 
"divide by zero")
+      }
+
+      checkExceptionInExpression[ArithmeticException](
+        Pmod(Literal(-7), Literal(0)), "divide by zero")

Review comment:
       done

##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala
##########
@@ -500,4 +524,53 @@ class ArithmeticExpressionSuite extends SparkFunSuite with 
ExpressionEvalHelper
       checkEvaluation(e6, 0.toByte)
     }
   }
+
+  private def testDecimalAndLongType(testFunc: (Int => Any) => Unit): Unit = {
+    testFunc(_.toLong)
+    testFunc(Decimal(_))
+  }
+
+  test("SPARK-33008: division by zero on divide-like operations returns 
incorrect result") {
+    withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
+      testDecimalAndDoubleType { convert =>

Review comment:
       done




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