yaooqinn commented on a change in pull request #31799:
URL: https://github.com/apache/spark/pull/31799#discussion_r592131789
##########
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:
It seems a mess at java-side already
```scala
scala> java.time.Duration.ofNanos(-1)
res6: java.time.Duration = PT-0.000000001S
scala> java.time.Duration.ofNanos(-1).get
get getClass getNano getSeconds getUnits
scala> java.time.Duration.ofNanos(-1).getNano
res9: Int = 999999999
scala> java.time.Duration.ofNanos(-1000).getNano
res10: Int = 999999000
scala> java.time.Duration.ofNanos(Int.MinValue).getNano
res12: Int = 852516352
scala> java.time.Duration.ofNanos(Int.M).getNano
MaxValue MinValue
scala> java.time.Duration.ofNanos(Int.MaxValue).getNano
res15: Int = 147483647
```
----------------------------------------------------------------
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]