Skip to content

Commit 04aabd8

Browse files
committed
Asia timezone fix
1 parent 93529a8 commit 04aabd8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ object Sequence {
26352635
var i = 0
26362636

26372637
while (t < exclusiveItem ^ stepSign < 0) {
2638-
arr(i) = fromLong(t / scale)
2638+
arr(i) = fromLong(Math.round(t / scale.toFloat))
26392639
i += 1
26402640
t = timestampAddInterval(
26412641
startMicros, i * stepMonths, i * stepDays, i * stepMicros, zoneId)
@@ -2698,7 +2698,7 @@ object Sequence {
26982698
| int $i = 0;
26992699
|
27002700
| while ($t < $exclusiveItem ^ $stepSign < 0) {
2701-
| $arr[$i] = ($elemType) ($t / ${scale}L);
2701+
| $arr[$i] = ($elemType) (Math.round($t / (float)${scale}L));
27022702
| $i += 1;
27032703
| $t = org.apache.spark.sql.catalyst.util.DateTimeUtils.timestampAddInterval(
27042704
| $startMicros, $i * $stepMonths, $i * $stepDays, $i * $stepMicros, $zid);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,7 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
18371837
checkEvaluation(ArrayIntersect(oneNull, empty), Seq.empty)
18381838
}
18391839

1840+
<<<<<<< HEAD
18401841
test("SPARK-31980: Start and end equal in month range") {
18411842
checkEvaluation(new Sequence(
18421843
Literal(Date.valueOf("2018-01-01")),
@@ -1853,5 +1854,17 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
18531854
Literal(Date.valueOf("2018-01-01")),
18541855
Literal(stringToInterval("interval 1 year"))),
18551856
Seq(Date.valueOf("2018-01-01")))
1857+
=======
1858+
test("SPARK-31982: sequence doesn't handle date increments that cross DST") {
1859+
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")))
1867+
})
1868+
>>>>>>> Asia timezone fix
18561869
}
18571870
}

0 commit comments

Comments
 (0)