Skip to content

Commit eae1747

Browse files
MaxGekkdongjoon-hyun
authored andcommitted
[SPARK-31959][SQL][TESTS][FOLLOWUP] Adopt the test "SPARK-31959: JST -> HKT at Asia/Hong_Kong in 1945" to outdated tzdb
### What changes were proposed in this pull request? Old JDK can have outdated time zone database in which `Asia/Hong_Kong` doesn't have timestamp overlapping in 1946 at all. This PR changes the test "SPARK-31959: JST -> HKT at Asia/Hong_Kong in 1945" in `RebaseDateTimeSuite`, and makes it tolerant to the case. ### Why are the changes needed? To fix the test failures on old JDK w/ outdated tzdb like on Jenkins machine `research-jenkins-worker-09`. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? By running the test on old JDK Closes #28832 from MaxGekk/HongKong-tz-1945-followup. Authored-by: Max Gekk <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 7f7b4dd commit eae1747

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/util/RebaseDateTimeSuite.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,22 +421,24 @@ class RebaseDateTimeSuite extends SparkFunSuite with Matchers with SQLHelper {
421421
var ldt = LocalDateTime.of(1945, 11, 18, 1, 30, 0)
422422
var earlierMicros = instantToMicros(ldt.atZone(hkZid).withEarlierOffsetAtOverlap().toInstant)
423423
var laterMicros = instantToMicros(ldt.atZone(hkZid).withLaterOffsetAtOverlap().toInstant)
424-
if (earlierMicros + MICROS_PER_HOUR != laterMicros) {
424+
var overlapInterval = MICROS_PER_HOUR
425+
if (earlierMicros + overlapInterval != laterMicros) {
425426
// Old JDK might have an outdated time zone database.
426427
// See https://bugs.openjdk.java.net/browse/JDK-8228469: "Hong Kong ... Its 1945 transition
427428
// from JST to HKT was on 11-18 at 02:00, not 09-15 at 00:00"
428429
expected = "1945-09-14 23:30:00.0"
429430
ldt = LocalDateTime.of(1945, 9, 14, 23, 30, 0)
430431
earlierMicros = instantToMicros(ldt.atZone(hkZid).withEarlierOffsetAtOverlap().toInstant)
431432
laterMicros = instantToMicros(ldt.atZone(hkZid).withLaterOffsetAtOverlap().toInstant)
432-
assert(earlierMicros + MICROS_PER_HOUR === laterMicros)
433+
// If time zone db doesn't have overlapping at all, set the overlap interval to zero.
434+
overlapInterval = laterMicros - earlierMicros
433435
}
434436
val rebasedEarlierMicros = rebaseGregorianToJulianMicros(hkZid, earlierMicros)
435437
val rebasedLaterMicros = rebaseGregorianToJulianMicros(hkZid, laterMicros)
436438
def toTsStr(micros: Long): String = toJavaTimestamp(micros).toString
437439
assert(toTsStr(rebasedEarlierMicros) === expected)
438440
assert(toTsStr(rebasedLaterMicros) === expected)
439-
assert(rebasedEarlierMicros + MICROS_PER_HOUR === rebasedLaterMicros)
441+
assert(rebasedEarlierMicros + overlapInterval === rebasedLaterMicros)
440442
// Check optimized rebasing
441443
assert(rebaseGregorianToJulianMicros(earlierMicros) === rebasedEarlierMicros)
442444
assert(rebaseGregorianToJulianMicros(laterMicros) === rebasedLaterMicros)

0 commit comments

Comments
 (0)