MaxGekk commented on a change in pull request #32314:
URL: https://github.com/apache/spark/pull/32314#discussion_r619134239



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
##########
@@ -402,6 +403,19 @@ case class DivideYMInterval(
   override def inputTypes: Seq[AbstractDataType] = Seq(YearMonthIntervalType, 
NumericType)
   override def dataType: DataType = YearMonthIntervalType
 
+  def checkDivideOverflow(month: Int, num: Any): Unit = {
+    if (month == Int.MinValue) {
+      num match {
+        case l: Long if l == -1L => throw 
QueryExecutionErrors.overflowInIntegralDivideError()
+        case number: Number if number.doubleValue() == -1.0D =>
+          throw QueryExecutionErrors.overflowInIntegralDivideError()
+        case decimal: Decimal if decimal.equals(Decimal.apply(-1)) =>

Review comment:
       Do we really need to handle Double and Decimal. For example, if we 
divide by -1.0D, we should get the result of the double type which should not 
overflow. or I am wrong?
   
   ```scala
   scala> Int.MinValue / -1
   res0: Int = -2147483648
   
   scala> Int.MinValue / -1.0D
   res1: Double = 2.147483648E9
   ```
   The overflow should happen when we cast double to int.




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