HyukjinKwon commented on code in PR #59239:
URL: https://github.com/apache/spark/pull/59239#discussion_r4221390320


##########
sql/core/src/test/scala/org/apache/spark/sql/BinBySuite.scala:
##########
@@ -428,6 +456,48 @@ class BinBySuite extends QueryTest with SharedSparkSession 
{
     }
   }
 
+  test("BIN BY raises DATETIME_OVERFLOW when the next bin index is not 
representable") {
+    val maxTimestamp = DateTimeUtils.microsToLocalDateTime(Long.MaxValue)
+    checkBinByDatetimeOverflow(
+      rangeStart = maxTimestamp,
+      rangeEnd = maxTimestamp,
+      binWidthSql = "INTERVAL '0.000001' SECOND",
+      originSql = "TIMESTAMP_NTZ '1970-01-01 00:00:00'")
+  }
+
+  test("BIN BY raises DATETIME_OVERFLOW when the range duration is not 
representable") {
+    checkBinByDatetimeOverflow(
+      rangeStart = DateTimeUtils.microsToLocalDateTime(Long.MinValue),
+      rangeEnd = DateTimeUtils.microsToLocalDateTime(Long.MaxValue),
+      binWidthSql = "INTERVAL '1' SECOND",
+      originSql = "TIMESTAMP_NTZ '1970-01-01 00:00:00'")
+  }
+
+  test("BIN BY raises DATETIME_OVERFLOW when locating a zero-length range bin 
overflows") {

Review Comment:
   **Nit (P3):** These 1 DAY cases overflow at `subtractExact(ts, origin)` 
inside `timeBucketFromTimestampDTInterval` (a MathUtils 
`SparkArithmeticException`) before any calendar-day arithmetic runs. In fact, 
all five new tests fail inside MathUtils. The one path that depends on 
`withBinByOverflow` catching the base `ArithmeticException` is the multi-day 
boundary computation, `timestampAddDayTime` -> `instantToMicros`, which throws 
a plain `java.lang.ArithmeticException`. No test reaches it, so narrowing the 
catch to `SparkArithmeticException` would keep the suite green while that path 
regressed to the raw 'long overflow'.
   
   That path is also reachable with ordinary timestamps. For example, rows in 
2020, `ALIGN TO TIMESTAMP_NTZ '2000-01-01 00:00:00'`, `BIN WIDTH INTERVAL 
'106751990' DAY`: here k = 0, and origin + width overflows in 
`instantToMicros`. Could you add a case like that through 
`checkBinByDatetimeOverflow`?
   
   **Verification:**
   - **Regression:** A multi-day-width BIN BY overflow whose failure originates 
in the calendar-day boundary computation (not in MathUtils) is asserted to 
raise DATETIME_OVERFLOW with the expected operation parameter.
   - **Behavior:** The existing BIN BY overflow and non-overflow tests continue 
to pass.



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

Reply via email to