Github user wajda commented on a diff in the pull request:
https://github.com/apache/spark/pull/21155#discussion_r197496354
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala
---
@@ -308,6 +313,292 @@ class CollectionExpressionsSuite extends
SparkFunSuite with ExpressionEvalHelper
ArrayMax(Literal.create(Seq(1.123, 0.1234, 1.121),
ArrayType(DoubleType))), 1.123)
}
+ test("Sequence") {
+ // test null handling
+
+ checkEvaluation(new Sequence(Literal(null, LongType), Literal(1L)),
null)
+ checkEvaluation(new Sequence(Literal(1L), Literal(null, LongType)),
null)
+ checkEvaluation(new Sequence(Literal(null, LongType), Literal(1L),
Literal(1L)), null)
+ checkEvaluation(new Sequence(Literal(1L), Literal(null, LongType),
Literal(1L)), null)
+ checkEvaluation(new Sequence(Literal(1L), Literal(1L), Literal(null,
LongType)), null)
+
+ // test sequence boundaries checking
+
+ checkExceptionInExpression[IllegalArgumentException](
+ new Sequence(Literal(Int.MinValue), Literal(Int.MaxValue),
Literal(1)),
+ EmptyRow, s"Too long sequence: 4294967296. Should be <=
${Int.MaxValue}")
+
+ checkExceptionInExpression[IllegalArgumentException](
+ new Sequence(Literal(1), Literal(2), Literal(0)), EmptyRow,
"boundaries: 1 to 2 by 0")
+ checkExceptionInExpression[IllegalArgumentException](
+ new Sequence(Literal(2), Literal(1), Literal(0)), EmptyRow,
"boundaries: 2 to 1 by 0")
+ checkExceptionInExpression[IllegalArgumentException](
+ new Sequence(Literal(2), Literal(1), Literal(1)), EmptyRow,
"boundaries: 2 to 1 by 1")
+ 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))
+ checkEvaluation(new Sequence(Literal(1), Literal(1), Literal(0)),
Seq(1))
+ checkEvaluation(new Sequence(Literal(1), Literal(1), Literal(1)),
Seq(1))
+ checkEvaluation(new Sequence(Literal(1), Literal(2), Literal(2)),
Seq(1))
+ checkEvaluation(new Sequence(Literal(1), Literal(0), Literal(-2)),
Seq(1))
+
+ // test sequence of different integral types (ascending and descending)
+
+ checkEvaluation(new Sequence(Literal(1L), Literal(3L), Literal(1L)),
Seq(1L, 2L, 3L))
+ checkEvaluation(new Sequence(Literal(-3), Literal(3), Literal(3)),
Seq(-3, 0, 3))
+ checkEvaluation(
+ new Sequence(Literal(3.toShort), Literal(-3.toShort),
Literal(-3.toShort)),
+ Seq(3.toShort, 0.toShort, -3.toShort))
+ checkEvaluation(
+ new Sequence(Literal(-1.toByte), Literal(-3.toByte),
Literal(-1.toByte)),
+ Seq(-1.toByte, -2.toByte, -3.toByte))
+ }
+
+ test("Sequence of timestamps") {
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(Timestamp.valueOf("2018-01-02 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 12 hours"))),
+ Seq(
+ Timestamp.valueOf("2018-01-01 00:00:00"),
+ Timestamp.valueOf("2018-01-01 12:00:00"),
+ Timestamp.valueOf("2018-01-02 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(Timestamp.valueOf("2018-01-02 00:00:01")),
+ Literal(CalendarInterval.fromString("interval 12 hours"))),
+ Seq(
+ Timestamp.valueOf("2018-01-01 00:00:00"),
+ Timestamp.valueOf("2018-01-01 12:00:00"),
+ Timestamp.valueOf("2018-01-02 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-02 00:00:00")),
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 12 hours").negate())),
+ Seq(
+ Timestamp.valueOf("2018-01-02 00:00:00"),
+ Timestamp.valueOf("2018-01-01 12:00:00"),
+ Timestamp.valueOf("2018-01-01 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-02 00:00:00")),
+ Literal(Timestamp.valueOf("2017-12-31 23:59:59")),
+ Literal(CalendarInterval.fromString("interval 12 hours").negate())),
+ Seq(
+ Timestamp.valueOf("2018-01-02 00:00:00"),
+ Timestamp.valueOf("2018-01-01 12:00:00"),
+ Timestamp.valueOf("2018-01-01 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(Timestamp.valueOf("2018-03-01 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 1 month"))),
+ Seq(
+ Timestamp.valueOf("2018-01-01 00:00:00"),
+ Timestamp.valueOf("2018-02-01 00:00:00"),
+ Timestamp.valueOf("2018-03-01 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-03-01 00:00:00")),
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 1 month").negate())),
+ Seq(
+ Timestamp.valueOf("2018-03-01 00:00:00"),
+ Timestamp.valueOf("2018-02-01 00:00:00"),
+ Timestamp.valueOf("2018-01-01 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-03-03 00:00:00")),
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 1 month 1
day").negate())),
+ Seq(
+ Timestamp.valueOf("2018-03-03 00:00:00"),
+ Timestamp.valueOf("2018-02-02 00:00:00"),
+ Timestamp.valueOf("2018-01-01 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-31 00:00:00")),
+ Literal(Timestamp.valueOf("2018-04-30 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 1 month"))),
+ Seq(
+ Timestamp.valueOf("2018-01-31 00:00:00"),
+ Timestamp.valueOf("2018-02-28 00:00:00"),
+ Timestamp.valueOf("2018-03-31 00:00:00"),
+ Timestamp.valueOf("2018-04-30 00:00:00")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(Timestamp.valueOf("2018-03-01 00:00:00")),
+ Literal(CalendarInterval.fromString("interval 1 month 1 second"))),
+ Seq(
+ Timestamp.valueOf("2018-01-01 00:00:00"),
+ Timestamp.valueOf("2018-02-01 00:00:01")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(Timestamp.valueOf("2018-03-01 00:04:06")),
+ Literal(CalendarInterval.fromString("interval 1 month 2 minutes 3
seconds"))),
+ Seq(
+ Timestamp.valueOf("2018-01-01 00:00:00"),
+ Timestamp.valueOf("2018-02-01 00:02:03"),
+ Timestamp.valueOf("2018-03-01 00:04:06")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2018-01-01 00:00:00")),
+ Literal(Timestamp.valueOf("2023-01-01 00:00:00")),
+ Literal(CalendarInterval.fromYearMonthString("1-5"))),
+ Seq(
+ Timestamp.valueOf("2018-01-01 00:00:00.000"),
+ Timestamp.valueOf("2019-06-01 00:00:00.000"),
+ Timestamp.valueOf("2020-11-01 00:00:00.000"),
+ Timestamp.valueOf("2022-04-01 00:00:00.000")))
+
+ checkEvaluation(new Sequence(
+ Literal(Timestamp.valueOf("2022-04-01 00:00:00")),
+ Literal(Timestamp.valueOf("2017-01-01 00:00:00")),
+ Literal(CalendarInterval.fromYearMonthString("1-5").negate())),
+ Seq(
+ Timestamp.valueOf("2022-04-01 00:00:00.000"),
+ Timestamp.valueOf("2020-11-01 00:00:00.000"),
+ Timestamp.valueOf("2019-06-01 00:00:00.000"),
+ Timestamp.valueOf("2018-01-01 00:00:00.000")))
+ }
+
+ test("Sequence on DST boundaries") {
+ val timeZone = TimeZone.getTimeZone("CET")
--- End diff --
renamed
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]