Skip to content

Commit 2a7caf7

Browse files
committed
Math.round overflow fix
1 parent 04aabd8 commit 2a7caf7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

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

26372637
while (t < exclusiveItem ^ stepSign < 0) {
2638-
arr(i) = fromLong(Math.round(t / scale.toFloat))
2638+
arr(i) = if (scale == 1) {
2639+
fromLong(t / scale)
2640+
} else {
2641+
fromLong(Math.round(t / scale.toFloat))
2642+
}
26392643
i += 1
26402644
t = timestampAddInterval(
26412645
startMicros, i * stepMonths, i * stepDays, i * stepMicros, zoneId)
@@ -2698,7 +2702,11 @@ object Sequence {
26982702
| int $i = 0;
26992703
|
27002704
| while ($t < $exclusiveItem ^ $stepSign < 0) {
2701-
| $arr[$i] = ($elemType) (Math.round($t / (float)${scale}L));
2705+
| if (${scale}L == 1L) {
2706+
| $arr[$i] = ($elemType) ($t / ${scale}L);
2707+
| } else {
2708+
| $arr[$i] = ($elemType) (Math.round($t / (float)${scale}L));
2709+
| }
27022710
| $i += 1;
27032711
| $t = org.apache.spark.sql.catalyst.util.DateTimeUtils.timestampAddInterval(
27042712
| $startMicros, $i * $stepMonths, $i * $stepDays, $i * $stepMicros, $zid);

0 commit comments

Comments
 (0)