Skip to content

Commit

Permalink
forbid time field steps for date start/end
Browse files Browse the repository at this point in the history
  • Loading branch information
TJX2014 committed Jun 29, 2020
1 parent 93529a8 commit 7021539
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,9 @@ object Sequence {
val stepDays = step.days
val stepMicros = step.microseconds

require(scale != MICROS_PER_DAY || stepMonths != 0 || stepDays != 0,
"sequence step must be a day interval if start and end values are dates")

if (stepMonths == 0 && stepMicros == 0 && scale == MICROS_PER_DAY) {
backedSequenceImpl.eval(start, stop, fromLong(stepDays))

Expand Down Expand Up @@ -2679,6 +2682,11 @@ object Sequence {
|final int $stepDays = $step.days;
|final long $stepMicros = $step.microseconds;
|
|if (${scale}L == ${MICROS_PER_DAY}L && $stepMonths == 0 && $stepDays == 0) {
| throw new IllegalArgumentException(
| "sequence step must be a day interval if start and end values are dates");
|}
|
|if ($stepMonths == 0 && $stepMicros == 0 && ${scale}L == ${MICROS_PER_DAY}L) {
| ${backedSequenceImpl.genCode(ctx, start, stop, stepDays, arr, elemType)};
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1854,4 +1854,16 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
Literal(stringToInterval("interval 1 year"))),
Seq(Date.valueOf("2018-01-01")))
}

test("SPARK-31982: Sequence step must be a day interval " +
"if start and end values are dates") {
val e = intercept[Exception](
checkEvaluation(Sequence(
Cast(Literal("2011-03-01"), DateType),
Cast(Literal("2011-04-01"), DateType),
Option(Literal(stringToInterval("interval 1 hour")))),
Seq(Date.valueOf("2011-03-01"), Date.valueOf("2011-04-01"))))
assert(e.getCause.getMessage.contains(
"sequence step must be a day interval if start and end values are dates"))
}
}

0 comments on commit 7021539

Please sign in to comment.