Skip to content

Commit 19d8c48

Browse files
committed
codegen epochDaysToMicros => daysToMicros
1 parent 076ebce commit 19d8c48

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,8 +2623,6 @@ object Sequence {
26232623
// about a month length in days and a day length in microseconds
26242624
val intervalStepInMicros =
26252625
stepMicros + stepMonths * microsPerMonth + stepDays * microsPerDay
2626-
val startMicros: Long = num.toLong(start) * scale
2627-
val stopMicros: Long = num.toLong(stop) * scale
26282626

26292627
// Date to timestamp is not equal from GMT and Chicago timezones
26302628
val (startMicros, stopMicros) = if (scale == 1) {
@@ -2699,8 +2697,19 @@ object Sequence {
26992697
|} else if ($stepMonths == 0 && $stepDays == 0 && ${scale}L == 1) {
27002698
| ${backedSequenceImpl.genCode(ctx, start, stop, stepMicros, arr, elemType)};
27012699
|} else {
2702-
| final long $startMicros = $start * ${scale}L;
2703-
| final long $stopMicros = $stop * ${scale}L;
2700+
| long $startMicros;
2701+
| long $stopMicros;
2702+
| if (${scale}L == 1L) {
2703+
| $startMicros = $start;
2704+
| $stopMicros = $stop;
2705+
| } else {
2706+
| $startMicros =
2707+
| org.apache.spark.sql.catalyst.util.DateTimeUtils.daysToMicros(
2708+
| (int)$start, $zid);
2709+
| $stopMicros =
2710+
| org.apache.spark.sql.catalyst.util.DateTimeUtils.daysToMicros(
2711+
| (int)$stop, $zid);
2712+
| }
27042713
|
27052714
| $sequenceLengthCode
27062715
|

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

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

1840-
<<<<<<< HEAD
18411840
test("SPARK-31980: Start and end equal in month range") {
18421841
checkEvaluation(new Sequence(
18431842
Literal(Date.valueOf("2018-01-01")),
@@ -1854,17 +1853,17 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
18541853
Literal(Date.valueOf("2018-01-01")),
18551854
Literal(stringToInterval("interval 1 year"))),
18561855
Seq(Date.valueOf("2018-01-01")))
1856+
}
18571857

18581858
test("SPARK-31982: sequence doesn't handle date increments that cross DST") {
1859-
Array("America/Chicago", "GMT", "Asia/Shanghai").foreach(tz => {
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(Date.valueOf("2011-03-01"), Date.valueOf("2011-04-01")))
1867-
}
1859+
Array("America/Chicago", "GMT").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")))
18681867
})
18691868
}
18701869
}

0 commit comments

Comments
 (0)