vranes commented on code in PR #55535:
URL: https://github.com/apache/spark/pull/55535#discussion_r3161766906
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/DateTimeUtils.scala:
##########
@@ -1059,4 +1059,59 @@ object DateTimeUtils extends SparkDateTimeUtils {
time, timePrecision, interval, intervalEndField)
}
}
+
+ /**
+ * DayTimeInterval bucketing: microsecond floor division against
`originMicros`.
+ * Returns `originMicros + floorDiv(tsMicros - originMicros, bucketMicros) *
bucketMicros`.
+ *
+ * `bucketMicros` must be positive; `TimeBucket.checkInputDataTypes` enforces
+ * this at analysis time.
+ *
+ * @param bucketMicros bucket size in microseconds.
+ * @param tsMicros timestamp to bucket, in microseconds since the epoch
(UTC).
+ * @param originMicros grid alignment anchor, in microseconds since the
epoch (UTC).
+ */
+ def timeBucketDTInterval(bucketMicros: Long, tsMicros: Long, originMicros:
Long): Long = {
+ val diff = Math.subtractExact(tsMicros, originMicros)
+ val bucketOffset = Math.multiplyExact(Math.floorDiv(diff, bucketMicros),
bucketMicros)
+ Math.addExact(originMicros, bucketOffset)
Review Comment:
Thanks! Switched to `MathUtils.subtractExact` / `multiplyExact` / `addExact`
/ `floorDiv` throughout `timeBucketDTInterval` and `timeBucketYMInterval`.
Updated the unit tests to `intercept[SparkArithmeticException]` to confirm the
wrapped error class.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]