Licht-T commented on code in PR #55610:
URL: https://github.com/apache/spark/pull/55610#discussion_r3193001584
##########
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.
+ val postSpring = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-03-10T03:30:00-07:00"), la).get
+ val expectedHour = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-03-10T03:00:00-07:00"), la).get
+ assert(DateTimeUtils.truncTimestamp(postSpring,
DateTimeUtils.TRUNC_TO_HOUR, la)
+ === expectedHour)
+ val expectedDay = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-03-10T00:00:00-08:00"), la).get
+ assert(DateTimeUtils.truncTimestamp(postSpring,
DateTimeUtils.TRUNC_TO_DAY, la)
+ === expectedDay)
+
+ // Fall-back in LA: 2024-11-03 01:30 occurs twice. Truncation to HOUR/DAY
should
+ // produce the same wall-clock boundary as the slow path regardless.
+ val postFall = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-11-03T01:30:00-08:00"), la).get
+ val expectedHour2 = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-11-03T01:00:00-08:00"), la).get
+ assert(DateTimeUtils.truncTimestamp(postFall, DateTimeUtils.TRUNC_TO_HOUR,
la)
+ === expectedHour2)
+ val expectedDay2 = DateTimeUtils.stringToTimestamp(
+ UTF8String.fromString("2024-11-03T00:00:00-07:00"), la).get
+ assert(DateTimeUtils.truncTimestamp(postFall, DateTimeUtils.TRUNC_TO_DAY,
la)
+ === expectedDay2)
+ }
+
+ test("SPARK-30766/30857: truncTimestamp before the epoch in HOUR/DAY") {
Review Comment:
Added these two lines into the `SPARK-33404` test.
--
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]