Skip to content

Commit 163a748

Browse files
committed
SPARK-23927: minor code style fixes
1 parent de044ea commit 163a748

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,9 +2650,9 @@ object Sequence {
26502650
private def getSequenceLength[U](start: U, stop: U, step: U)(implicit num: Integral[U]): Int = {
26512651
import num._
26522652
require(
2653-
step > num.zero && start <= stop
2654-
|| step < num.zero && start >= stop
2655-
|| step == 0 && start == stop,
2653+
(step > num.zero && start <= stop)
2654+
|| (step < num.zero && start >= stop)
2655+
|| (step == 0 && start == stop),
26562656
s"Illegal sequence boundaries: $start to $stop by $step")
26572657

26582658
val len = if (start == stop) 1L else 1L + (stop.toLong - start.toLong) / step.toLong
@@ -2672,9 +2672,9 @@ object Sequence {
26722672
len: String): String = {
26732673
val longLen = ctx.freshName("longLen")
26742674
s"""
2675-
|if (!($step > 0 && $start <= $stop||
2676-
| $step < 0 && $start >= $stop||
2677-
| $step == 0 && $start == $stop)) {
2675+
|if (!(($step > 0 && $start <= $stop) ||
2676+
| ($step < 0 && $start >= $stop) ||
2677+
| ($step == 0 && $start == $stop))) {
26782678
| throw new IllegalArgumentException(
26792679
| "Illegal sequence boundaries: " + $start + " to " + $stop + " by " + $step);
26802680
|}

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
478478
ArrayMax(Literal.create(Seq(1.123, 0.1234, 1.121), ArrayType(DoubleType))), 1.123)
479479
}
480480

481-
test("Sequence") {
481+
test("Sequence of numbers") {
482482
// test null handling
483483

484484
checkEvaluation(new Sequence(Literal(null, LongType), Literal(1L)), null)
@@ -502,21 +502,6 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
502502
checkExceptionInExpression[IllegalArgumentException](
503503
new Sequence(Literal(1), Literal(2), Literal(-1)), EmptyRow, "boundaries: 1 to 2 by -1")
504504

505-
checkExceptionInExpression[IllegalArgumentException](
506-
new Sequence(
507-
Literal(Date.valueOf("1970-01-02")),
508-
Literal(Date.valueOf("1970-01-01")),
509-
Literal(CalendarInterval.fromString("interval 1 day"))),
510-
EmptyRow, "sequence boundaries: 1 to 0 by 1")
511-
512-
checkExceptionInExpression[IllegalArgumentException](
513-
new Sequence(
514-
Literal(Date.valueOf("1970-01-01")),
515-
Literal(Date.valueOf("1970-02-01")),
516-
Literal(CalendarInterval.fromString("interval 1 month").negate())),
517-
EmptyRow,
518-
s"sequence boundaries: 0 to 2678400000000 by -${28 * CalendarInterval.MICROS_PER_DAY}")
519-
520505
// test sequence with one element (zero step or equal start and stop)
521506

522507
checkEvaluation(new Sequence(Literal(1), Literal(1), Literal(-1)), Seq(1))
@@ -650,7 +635,7 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
650635
}
651636

652637
test("Sequence on DST boundaries") {
653-
val timeZone = TimeZone.getTimeZone("CET")
638+
val timeZone = TimeZone.getTimeZone("Europe/Prague")
654639
val dstOffset = timeZone.getDSTSavings
655640

656641
def noDST(t: Timestamp): Timestamp = new Timestamp(t.getTime - dstOffset)
@@ -721,6 +706,21 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
721706
Date.valueOf("2019-06-01"),
722707
Date.valueOf("2020-11-01"),
723708
Date.valueOf("2022-04-01")))
709+
710+
checkExceptionInExpression[IllegalArgumentException](
711+
new Sequence(
712+
Literal(Date.valueOf("1970-01-02")),
713+
Literal(Date.valueOf("1970-01-01")),
714+
Literal(CalendarInterval.fromString("interval 1 day"))),
715+
EmptyRow, "sequence boundaries: 1 to 0 by 1")
716+
717+
checkExceptionInExpression[IllegalArgumentException](
718+
new Sequence(
719+
Literal(Date.valueOf("1970-01-01")),
720+
Literal(Date.valueOf("1970-02-01")),
721+
Literal(CalendarInterval.fromString("interval 1 month").negate())),
722+
EmptyRow,
723+
s"sequence boundaries: 0 to 2678400000000 by -${28 * CalendarInterval.MICROS_PER_DAY}")
724724
}
725725
}
726726

0 commit comments

Comments
 (0)