Github user raghavgautam commented on a diff in the pull request: https://github.com/apache/spark/pull/22414#discussion_r217793474 --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/TimeWindowSuite.scala --- @@ -122,11 +122,57 @@ class TimeWindowSuite extends SparkFunSuite with ExpressionEvalHelper with Priva } } + test("windowDuration and slideDuration should be positive.") { + import org.scalatest.prop.TableDrivenPropertyChecks.{Table, forAll => forAllRows} + val fractions = Table( + ("windowDuration", "slideDuration"), // First tuple defines column names + ("-2 seconds", "1 seconds"), + ("1 seconds", "-2 seconds"), + ("0 seconds", "1 seconds"), + ("1 seconds", "0 seconds"), + ("-2 seconds", "-2 seconds"), + ("-2 seconds", "-2 hours"), + ("0 seconds", "0 seconds"), + (-2L, 2L), + (2L, -2L), + (-2, 2), + (2, -2) + ) + forAllRows(fractions) { (windowDuration: Any, slideDuration: Any) => + logInfo(s"windowDuration = $windowDuration slideDuration = $slideDuration") + + val thrown = intercept[IllegalArgumentException] { + (windowDuration, slideDuration) match { + case (wd: String, sd: String) => TimeWindow(Literal(10L), wd, sd, "0 seconds") + case (wd: Long, sd: Long) => TimeWindow(Literal(10L), wd, sd, 0) + case (wd: Int, sd: Int) => TimeWindow(Literal(10L), wd, sd, 0) + } + + } + def isNonPositive(s: Any): Boolean = { + val trimmed = s.toString.trim + trimmed.startsWith("-") || trimmed.startsWith("0") + } + val expectedMsg = + if (isNonPositive(windowDuration)) { + s"requirement failed: The window duration must be a " + + s"positive integer, long or string literal, found: ${windowDuration}" + } else if (isNonPositive(slideDuration)) { + s"requirement failed: The slide duration must be a " + --- End diff -- Done.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org