Skip to content

Commit d732984

Browse files
committed
add withDefaultTimeZone and epochDaysToMicros => DateTimeUtils.epochDaysToMicros
1 parent d23d155 commit d732984

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,6 +2625,16 @@ object Sequence {
26252625
stepMicros + stepMonths * microsPerMonth + stepDays * microsPerDay
26262626
val startMicros: Long = num.toLong(start) * scale
26272627
val stopMicros: Long = num.toLong(stop) * scale
2628+
2629+
// Date to timestamp is not equal from GMT and Chicago timezones
2630+
val (startMicros, stopMicros) = if (scale == 1) {
2631+
(num.toLong(start), num.toLong(stop))
2632+
}
2633+
else {
2634+
(DateTimeUtils.epochDaysToMicros(num.toInt(start), zoneId),
2635+
DateTimeUtils.epochDaysToMicros(num.toInt(stop), zoneId))
2636+
}
2637+
26282638
val maxEstimatedArrayLength =
26292639
getSequenceLength(startMicros, stopMicros, intervalStepInMicros)
26302640

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,17 +1854,18 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
18541854
Literal(Date.valueOf("2018-01-01")),
18551855
Literal(stringToInterval("interval 1 year"))),
18561856
Seq(Date.valueOf("2018-01-01")))
1857-
=======
1857+
18581858
test("SPARK-31982: sequence doesn't handle date increments that cross DST") {
18591859
Array("America/Chicago", "GMT", "Asia/Shanghai").foreach(tz => {
1860-
checkEvaluation(Sequence(
1861-
Cast(Literal("2011-03-01"), DateType),
1862-
Cast(Literal("2011-04-01"), DateType),
1863-
Option(Literal(stringToInterval("interval 1 month"))),
1864-
Option(tz)),
1865-
Seq(
1866-
Date.valueOf("2011-03-01"), Date.valueOf("2011-04-01")))
1860+
DateTimeTestUtils.withDefaultTimeZone(DateTimeUtils.getTimeZone(tz).toZoneId) {
1861+
checkEvaluation(Sequence(
1862+
Cast(Literal("2011-03-01"), DateType),
1863+
Cast(Literal("2011-04-01"), DateType),
1864+
Option(Literal(stringToInterval("interval 1 month"))),
1865+
Option(tz)),
1866+
Seq(
1867+
Date.valueOf("2011-03-01"), Date.valueOf("2011-04-01")))
1868+
}
18671869
})
1868-
>>>>>>> Asia timezone fix
18691870
}
18701871
}

0 commit comments

Comments
 (0)