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/03/11 06:56:48 UTC

[GitHub] [spark] MaxGekk commented on a change in pull request #31799: [SPARK-34695][SQL] Fix long overflow in conversion of minimum duration to microseconds

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -779,9 +782,14 @@ object IntervalUtils {
    * @throws ArithmeticException If numeric overflow occurs
    */
   def durationToMicros(duration: Duration): Long = {
-    val us = Math.multiplyExact(duration.getSeconds, MICROS_PER_SECOND)
-    val result = Math.addExact(us, duration.getNano / NANOS_PER_MICROS)
-    result
+    val seconds = duration.getSeconds
+    if (seconds == minDurationSeconds) {
+      val us = (minDurationSeconds + 1) * MICROS_PER_SECOND
+      Math.addExact(us, (duration.getNano - NANOS_PER_SECOND) / NANOS_PER_MICROS)

Review comment:
       According to Java doc for `Duration.getNano`:
   ```java
        * @return the nanoseconds within the second part of the length of the duration, from 0 to 999,999,999
        */
       public int getNano() {
           return nanos;
       }
   ```




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