You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/04/23 11:08:56 UTC

[GitHub] [spark] MaxGekk commented on a change in pull request #32314: [SPARK-35169][SQL] Fix wrong result of min ANSI interval division by -1

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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org