You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/03/09 19:05:08 UTC

[GitHub] [spark] MaxGekk opened a new pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

MaxGekk opened a new pull request #31789:
URL: https://github.com/apache/spark/pull/31789


   ### What changes were proposed in this pull request?
   Extend the `Add`, `Subtract` and `UnaryMinus` expression to support `DayTimeIntervalType` and `YearMonthIntervalType` added by #31614.
   
   ### Why are the changes needed?
   To conform to the ANSI SQL standard which defines `-/+` over intervals:
   <img width="822" alt="Screenshot 2021-03-09 at 21 59 22" src="https://user-images.githubusercontent.com/1580697/110523128-bd50ea80-8122-11eb-9982-782da0088d27.png">
    
   
   ### Does this PR introduce _any_ user-facing change?
   Should not since new types have not been released yet.
   
   ### How was this patch tested?
   By running new tests in the test suites:
   ```
   $ build/sbt "test:testOnly *ArithmeticExpressionSuite"
   $ build/sbt "test:testOnly *ColumnExpressionSuite"
   ```


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794447731


   Kubernetes integration test status success
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40490/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] MaxGekk commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796502406


   @cloud-fan @HyukjinKwon @yaooqinn Any more feedback for the changes?


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794409650


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40490/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] MaxGekk commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r592113599



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala
##########
@@ -2375,4 +2376,16 @@ class ColumnExpressionSuite extends QueryTest with SharedSparkSession {
     assert(e2.getCause.isInstanceOf[RuntimeException])
     assert(e2.getCause.getMessage == "hello")
   }
+
+  test("SPARK-34677: negate/add/subtract year-month and day-time intervals") {
+    import testImplicits._
+    val df = Seq((Period.ofMonths(10), Duration.ofDays(10), Period.ofMonths(1), Duration.ofDays(1)))
+      .toDF("year-month-A", "day-time-A", "year-month-B", "day-time-B")
+    val negatedDF = df.select(-$"year-month-A", -$"day-time-A")
+    checkAnswer(negatedDF, Row(Period.ofMonths(-10), Duration.ofDays(-10)))
+    val sumDF = df.select($"year-month-A" + $"year-month-B", $"day-time-A" + $"day-time-B")

Review comment:
       > does sum function accept the new interval types?
   
   `sum` operates over `NumericType` only, see https://github.com/apache/spark/blob/3a299aa6480ac22501512cd0310d31a441d7dfdc/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/aggregate/Sum.scala#L49 . If you think we should support new intervals in it, let's do that separately since this PR is about operators `+`/`-`. 




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794464684


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40490/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-795023365


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135926/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-795052568


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40510/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-795061494


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40510/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794398365






----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796558002


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40550/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794398365


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135907/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794748490


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135908/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794528606


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40491/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r592107298



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala
##########
@@ -2375,4 +2376,16 @@ class ColumnExpressionSuite extends QueryTest with SharedSparkSession {
     assert(e2.getCause.isInstanceOf[RuntimeException])
     assert(e2.getCause.getMessage == "hello")
   }
+
+  test("SPARK-34677: negate/add/subtract year-month and day-time intervals") {
+    import testImplicits._
+    val df = Seq((Period.ofMonths(10), Duration.ofDays(10), Period.ofMonths(1), Duration.ofDays(1)))
+      .toDF("year-month-A", "day-time-A", "year-month-B", "day-time-B")
+    val negatedDF = df.select(-$"year-month-A", -$"day-time-A")
+    checkAnswer(negatedDF, Row(Period.ofMonths(-10), Duration.ofDays(-10)))
+    val sumDF = df.select($"year-month-A" + $"year-month-B", $"day-time-A" + $"day-time-B")

Review comment:
       `sumDF` -> `addDF`




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r591100803



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -173,6 +180,11 @@ abstract class BinaryArithmetic extends BinaryOperator with NullIntolerant {
   def calendarIntervalMethod: String =
     sys.error("BinaryArithmetics must override either calendarIntervalMethod or genCode")
 
+  /** Name of the function for this expression on [[DayTimeIntervalType]] and
+   *  [[YearMonthIntervalType]] types. */
+  def intervalMethod: String =

Review comment:
       Shall we reuse `exactMathMethod`?




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796533876


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135966/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794502985


   **[Test build #135908 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/135908/testReport)** for PR 31789 at commit [`18b1db3`](https://github.com/apache/spark/commit/18b1db30ed4681752827b3f72cda8083aa50cf48).


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r591124725



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -173,6 +180,11 @@ abstract class BinaryArithmetic extends BinaryOperator with NullIntolerant {
   def calendarIntervalMethod: String =
     sys.error("BinaryArithmetics must override either calendarIntervalMethod or genCode")
 
+  /** Name of the function for this expression on [[DayTimeIntervalType]] and
+   *  [[YearMonthIntervalType]] types. */
+  def intervalMethod: String =

Review comment:
       we can use `assert` to make sure it's defined for interval types.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794502985


   **[Test build #135908 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/135908/testReport)** for PR 31789 at commit [`18b1db3`](https://github.com/apache/spark/commit/18b1db30ed4681752827b3f72cda8083aa50cf48).


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-795067155


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40510/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796622590


   thanks, merging to master!


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] MaxGekk commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r592206974



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala
##########
@@ -2375,4 +2376,16 @@ class ColumnExpressionSuite extends QueryTest with SharedSparkSession {
     assert(e2.getCause.isInstanceOf[RuntimeException])
     assert(e2.getCause.getMessage == "hello")
   }
+
+  test("SPARK-34677: negate/add/subtract year-month and day-time intervals") {
+    import testImplicits._
+    val df = Seq((Period.ofMonths(10), Duration.ofDays(10), Period.ofMonths(1), Duration.ofDays(1)))
+      .toDF("year-month-A", "day-time-A", "year-month-B", "day-time-B")
+    val negatedDF = df.select(-$"year-month-A", -$"day-time-A")
+    checkAnswer(negatedDF, Row(Period.ofMonths(-10), Duration.ofDays(-10)))
+    val sumDF = df.select($"year-month-A" + $"year-month-B", $"day-time-A" + $"day-time-B")

Review comment:
       I opened the JIRA SPARK-34716 to don't forget about it.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r592107402



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/ColumnExpressionSuite.scala
##########
@@ -2375,4 +2376,16 @@ class ColumnExpressionSuite extends QueryTest with SharedSparkSession {
     assert(e2.getCause.isInstanceOf[RuntimeException])
     assert(e2.getCause.getMessage == "hello")
   }
+
+  test("SPARK-34677: negate/add/subtract year-month and day-time intervals") {
+    import testImplicits._
+    val df = Seq((Period.ofMonths(10), Duration.ofDays(10), Period.ofMonths(1), Duration.ofDays(1)))
+      .toDF("year-month-A", "day-time-A", "year-month-B", "day-time-B")
+    val negatedDF = df.select(-$"year-month-A", -$"day-time-A")
+    checkAnswer(negatedDF, Row(Period.ofMonths(-10), Duration.ofDays(-10)))
+    val sumDF = df.select($"year-month-A" + $"year-month-B", $"day-time-A" + $"day-time-B")

Review comment:
       does `sum` function accept the new interval types?




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r592106806



##########
File path: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ArithmeticExpressionSuite.scala
##########
@@ -576,4 +577,41 @@ class ArithmeticExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
       }
     }
   }
+
+  test("SPARK-34677: exact add and subtract of day-time and year-month intervals") {
+    checkExceptionInExpression[ArithmeticException](
+      UnaryMinus(Literal.create(Period.ofMonths(Int.MinValue), YearMonthIntervalType)),
+      "overflow")
+    Seq(true, false).foreach { failOnError =>

Review comment:
       `UnaryMinus` has the `failOnError` flag as well. Shall we move it inside as well? 




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796533876


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135966/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan closed pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #31789:
URL: https://github.com/apache/spark/pull/31789


   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] MaxGekk commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794947184


   @HyukjinKwon @cloud-fan Could you take a look at this PR, please.


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] MaxGekk commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r591118022



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -173,6 +180,11 @@ abstract class BinaryArithmetic extends BinaryOperator with NullIntolerant {
   def calendarIntervalMethod: String =
     sys.error("BinaryArithmetics must override either calendarIntervalMethod or genCode")
 
+  /** Name of the function for this expression on [[DayTimeIntervalType]] and
+   *  [[YearMonthIntervalType]] types. */
+  def intervalMethod: String =

Review comment:
       Sure, since `exactMathMethod` is always defined in the expressions, we can directly invoke `exactMathMethod.get`.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794739281


   **[Test build #135908 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/135908/testReport)** for PR 31789 at commit [`18b1db3`](https://github.com/apache/spark/commit/18b1db30ed4681752827b3f72cda8083aa50cf48).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-795023365


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135926/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794748490


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/135908/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] MaxGekk commented on a change in pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #31789:
URL: https://github.com/apache/spark/pull/31789#discussion_r591118022



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -173,6 +180,11 @@ abstract class BinaryArithmetic extends BinaryOperator with NullIntolerant {
   def calendarIntervalMethod: String =
     sys.error("BinaryArithmetics must override either calendarIntervalMethod or genCode")
 
+  /** Name of the function for this expression on [[DayTimeIntervalType]] and
+   *  [[YearMonthIntervalType]] types. */
+  def intervalMethod: String =

Review comment:
       Sure, since `exactMathMethod` is always defined in the expressions, we can directly invoke `exactMathMethod.get`. Though I can add a guard `if exactMathMethod.isDefined`.




----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796558002


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40550/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-795067155


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40510/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796553492


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40550/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-794528606


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40491/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #31789: [SPARK-34677][SQL] Support the `+`/`-` operators over ANSI SQL intervals

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31789:
URL: https://github.com/apache/spark/pull/31789#issuecomment-796551052


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40550/
   


----------------------------------------------------------------
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:
users@infra.apache.org



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