Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
SPARK-23927: minor code style fixes
  • Loading branch information
wajda committed Jun 26, 2018
commit 163a748c5fe6a27d88457f20cff63b6a5416089d
Original file line number Diff line number Diff line change
Expand Up @@ -2650,9 +2650,9 @@ object Sequence {
private def getSequenceLength[U](start: U, stop: U, step: U)(implicit num: Integral[U]): Int = {
import num._
require(
step > num.zero && start <= stop
|| step < num.zero && start >= stop
|| step == 0 && start == stop,
(step > num.zero && start <= stop)
|| (step < num.zero && start >= stop)
|| (step == 0 && start == stop),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num.zero instead of 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Although I wonder what difference it makes besides the readability? Doesn't equals(0) work consistently on every numeric types in Scala? Or is it related to autoboxing somehow? It's not very clear to me in this context. Thanks.

s"Illegal sequence boundaries: $start to $stop by $step")

val len = if (start == stop) 1L else 1L + (stop.toLong - start.toLong) / step.toLong
Expand All @@ -2672,9 +2672,9 @@ object Sequence {
len: String): String = {
val longLen = ctx.freshName("longLen")
s"""
|if (!($step > 0 && $start <= $stop||
| $step < 0 && $start >= $stop||
| $step == 0 && $start == $stop)) {
|if (!(($step > 0 && $start <= $stop) ||
| ($step < 0 && $start >= $stop) ||
| ($step == 0 && $start == $stop))) {
| throw new IllegalArgumentException(
| "Illegal sequence boundaries: " + $start + " to " + $stop + " by " + $step);
|}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
ArrayMax(Literal.create(Seq(1.123, 0.1234, 1.121), ArrayType(DoubleType))), 1.123)
}

test("Sequence") {
test("Sequence of numbers") {
// test null handling

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

checkExceptionInExpression[IllegalArgumentException](
new Sequence(
Literal(Date.valueOf("1970-01-02")),
Literal(Date.valueOf("1970-01-01")),
Literal(CalendarInterval.fromString("interval 1 day"))),
EmptyRow, "sequence boundaries: 1 to 0 by 1")

checkExceptionInExpression[IllegalArgumentException](
new Sequence(
Literal(Date.valueOf("1970-01-01")),
Literal(Date.valueOf("1970-02-01")),
Literal(CalendarInterval.fromString("interval 1 month").negate())),
EmptyRow,
s"sequence boundaries: 0 to 2678400000000 by -${28 * CalendarInterval.MICROS_PER_DAY}")

// test sequence with one element (zero step or equal start and stop)

checkEvaluation(new Sequence(Literal(1), Literal(1), Literal(-1)), Seq(1))
Expand Down Expand Up @@ -650,7 +635,7 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
}

test("Sequence on DST boundaries") {
val timeZone = TimeZone.getTimeZone("CET")
val timeZone = TimeZone.getTimeZone("Europe/Prague")
val dstOffset = timeZone.getDSTSavings

def noDST(t: Timestamp): Timestamp = new Timestamp(t.getTime - dstOffset)
Expand Down Expand Up @@ -721,6 +706,21 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
Date.valueOf("2019-06-01"),
Date.valueOf("2020-11-01"),
Date.valueOf("2022-04-01")))

checkExceptionInExpression[IllegalArgumentException](
new Sequence(
Literal(Date.valueOf("1970-01-02")),
Literal(Date.valueOf("1970-01-01")),
Literal(CalendarInterval.fromString("interval 1 day"))),
EmptyRow, "sequence boundaries: 1 to 0 by 1")

checkExceptionInExpression[IllegalArgumentException](
new Sequence(
Literal(Date.valueOf("1970-01-01")),
Literal(Date.valueOf("1970-02-01")),
Literal(CalendarInterval.fromString("interval 1 month").negate())),
EmptyRow,
s"sequence boundaries: 0 to 2678400000000 by -${28 * CalendarInterval.MICROS_PER_DAY}")
}
}

Expand Down