Licht-T commented on code in PR #55610:
URL: https://github.com/apache/spark/pull/55610#discussion_r3193005947
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/DateTimeUtilsSuite.scala:
##########
@@ -766,6 +766,97 @@ class DateTimeUtilsSuite extends SparkFunSuite with
Matchers with SQLHelper {
}
}
+ test("truncTimestamp with sub-hour zone offsets") {
+ // Asia/Kolkata (+05:30) and Asia/Kathmandu (+05:45) are not aligned to
HOUR in UTC.
+ // The fast path applies the offset as part of its arithmetic, so HOUR/DAY
truncation
+ // produces the correct local-aligned result without needing the slow path.
+ val kolkata = getZoneId("Asia/Kolkata")
+ val ts = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-01-15T09:42:17.123456+05:30"), kolkata).get
+ val expectedHour = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-01-15T09:00:00+05:30"), kolkata).get
+ assert(DateTimeUtils.truncTimestamp(ts, DateTimeUtils.TRUNC_TO_HOUR,
kolkata) === expectedHour)
+ val expectedDay = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-01-15T00:00:00+05:30"), kolkata).get
+ assert(DateTimeUtils.truncTimestamp(ts, DateTimeUtils.TRUNC_TO_DAY,
kolkata) === expectedDay)
+
+ val kathmandu = getZoneId("Asia/Kathmandu")
+ val ts2 = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-01-15T09:42:17.123456+05:45"), kathmandu).get
+ val expectedHour2 = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-01-15T09:00:00+05:45"), kathmandu).get
+ assert(DateTimeUtils.truncTimestamp(
+ ts2, DateTimeUtils.TRUNC_TO_HOUR, kathmandu) === expectedHour2)
+ }
+
+ test("truncTimestamp across DST transitions") {
+ val la = getZoneId("America/Los_Angeles")
+ // Spring-forward in LA: 2024-03-10 02:00 PDT does not exist; 02:30 local
maps to
+ // 2024-03-10 03:30 PDT in wall-clock terms. Use an instant just after the
transition
+ // so HOUR/DAY truncation candidate falls into the pre-transition offset
window.
Review Comment:
Changed the comment as per your suggestion.
--
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]