[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-07-05 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r450009801



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -2612,6 +2612,11 @@ object Sequence {
   val stepDays = step.days
   val stepMicros = step.microseconds
 
+  if (scale == MICROS_PER_DAY && 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 == MICROS_PER_DAY) {

Review comment:
   We can probably add comments for each branch. For example, this branch 
is for adding days to date start/end.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-07-05 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r450009133



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -2612,6 +2612,11 @@ object Sequence {
   val stepDays = step.days
   val stepMicros = step.microseconds
 
+  if (scale == MICROS_PER_DAY && stepMonths == 0 && stepDays == 0) {
+throw new IllegalArgumentException(

Review comment:
   I asked to throw an exception explicitly, to match the codegen code.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-07-03 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r449456120



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -2674,11 +2679,24 @@ object Sequence {
|${genSequenceLengthCode(ctx, startMicros, stopMicros, 
intervalInMicros, arrLength)}
   """.stripMargin
 
+  val check = if (scale == MICROS_PER_DAY) {
+s"""
+   |if ($stepMonths == 0 && $stepDays == 0) {
+   |   throw new IllegalArgumentException(
+   | "sequence step must be a day interval if start and end values 
are dates");
+   |}
+  """.stripMargin
+} else {
+  ""
+}
+
   s"""
  |final int $stepMonths = $step.months;
  |final int $stepDays = $step.days;
  |final long $stepMicros = $step.microseconds;
  |
+ |  $check

Review comment:
   nit: no need to add 2 space indentation here.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-07-02 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r448960031



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -2674,11 +2679,24 @@ object Sequence {
|${genSequenceLengthCode(ctx, startMicros, stopMicros, 
intervalInMicros, arrLength)}
   """.stripMargin
 
+  val check = if (scale == MICROS_PER_DAY) {
+s"""
+   if ($stepMonths == 0 && $stepDays == 0) {
+  throw new IllegalArgumentException(

Review comment:
   nit: for generated code, we shal use the multiline string syntax:
   ```
   s"""
 |if ...
 |""".stripMargin
   ```





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-07-02 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r448960031



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -2674,11 +2679,24 @@ object Sequence {
|${genSequenceLengthCode(ctx, startMicros, stopMicros, 
intervalInMicros, arrLength)}
   """.stripMargin
 
+  val check = if (scale == MICROS_PER_DAY) {
+s"""
+   if ($stepMonths == 0 && $stepDays == 0) {
+  throw new IllegalArgumentException(

Review comment:
   nit: for generated code, we shall use the multiline string syntax:
   ```
   s"""
 |if ...
 |""".stripMargin
   ```





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-06-30 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r447466465



##
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala
##
@@ -1854,4 +1854,16 @@ class CollectionExpressionsSuite extends SparkFunSuite 
with ExpressionEvalHelper
   Literal(stringToInterval("interval 1 year"))),
   Seq(Date.valueOf("2018-01-01")))
   }
+
+  test("SPARK-32133: Sequence step must be a day interval " +
+"if start and end values are dates") {
+val e = intercept[Exception](
+  checkEvaluation(Sequence(

Review comment:
   we should use `checkExceptionInExpression` for error tests.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-06-30 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r447465413



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -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")

Review comment:
   let's use
   ```
   if (...) throw new IllegalArgumentException
   ```
   
   to be more consistent with the codegen version.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] cloud-fan commented on a change in pull request #28926: [SPARK-32133][SQL] Forbid time field steps for date start/end in Sequence

2020-06-30 Thread GitBox


cloud-fan commented on a change in pull request #28926:
URL: https://github.com/apache/spark/pull/28926#discussion_r447464759



##
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##
@@ -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) {

Review comment:
   the `scale` is known before generating the code. We can do better
   ```
   val check = if (scale == MICROS_PER_DAY) {
 s"""
   if ($stepMonths == 0 && $stepDays == 0) ...
  """
   } else {
 ""
   }
   ```





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org