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/25 15:47:24 UTC

[GitHub] [spark] MaxGekk opened a new pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   ### What changes were proposed in this pull request?
   1. Add new expression `DivideYMInterval` which multiplies a `YearMonthIntervalType` expression by a `NumericType` expression including ByteType, ShortType, IntegerType, LongType, FloatType, DoubleType, DecimalType.
   2. Extend binary arithmetic rules to support `year-month interval / numeric`.
   
   ### Why are the changes needed?
   To conform the ANSI SQL standard which requires such operation over year-month intervals:
   <img width="656" alt="Screenshot 2021-03-25 at 18 44 58" src="https://user-images.githubusercontent.com/1580697/112501559-68f07080-8d9a-11eb-8781-66e6631bb7ef.png">
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   ### How was this patch tested?
   By running new tests:
   ```
   $ build/sbt "test:testOnly *IntervalExpressionsSuite"
   $ 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] AmplabJenkins commented on pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


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


-- 
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] tanelk commented on pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   Perhaps a bit broader question. When adding new expressiones, should we keep in mind places like `PushFoldableIntoBranches#supportedBinaryExpression`? Or should they be handled separately?


-- 
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] tanelk edited a comment on pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

Posted by GitBox <gi...@apache.org>.
tanelk edited a comment on pull request #31961:
URL: https://github.com/apache/spark/pull/31961#issuecomment-807122141


   Perhaps a bit broader question. When adding new expressions, should we keep in mind places like `PushFoldableIntoBranches#supportedBinaryExpression`? Or should they be handled separately?


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   **[Test build #136530 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136530/testReport)** for PR 31961 at commit [`92deb16`](https://github.com/apache/spark/commit/92deb160ad92c69092a8dfa343a8f608680404c2).
    * 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 removed a comment on pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


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


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
##########
@@ -341,3 +341,53 @@ case class MultiplyDTInterval(
 
   override def toString: String = s"($left * $right)"
 }
+
+// Divide an year-month interval by a numeric
+case class DivideYMInterval(
+    interval: Expression,
+    num: Expression)
+  extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant with Serializable {
+  override def left: Expression = interval
+  override def right: Expression = num
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(YearMonthIntervalType, NumericType)
+  override def dataType: DataType = YearMonthIntervalType
+
+  @transient
+  private lazy val evalFunc: (Int, Any) => Any = right.dataType match {
+    case LongType => (months: Int, num) =>
+      LongMath.divide(months, num.asInstanceOf[Long], RoundingMode.HALF_UP).toInt

Review comment:
       `months` is int, the result of `/` must fit to int too. So, `toInt` should be safe.




-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


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


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   **[Test build #136530 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136530/testReport)** for PR 31961 at commit [`92deb16`](https://github.com/apache/spark/commit/92deb160ad92c69092a8dfa343a8f608680404c2).


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
##########
@@ -341,3 +341,53 @@ case class MultiplyDTInterval(
 
   override def toString: String = s"($left * $right)"
 }
+
+// Divide an year-month interval by a numeric
+case class DivideYMInterval(
+    interval: Expression,
+    num: Expression)
+  extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant with Serializable {
+  override def left: Expression = interval
+  override def right: Expression = num
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(YearMonthIntervalType, NumericType)
+  override def dataType: DataType = YearMonthIntervalType
+
+  @transient
+  private lazy val evalFunc: (Int, Any) => Any = right.dataType match {
+    case LongType => (months: Int, num) =>
+      LongMath.divide(months, num.asInstanceOf[Long], RoundingMode.HALF_UP).toInt

Review comment:
       I added comments in https://github.com/apache/spark/pull/31972




-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


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


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   **[Test build #136530 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136530/testReport)** for PR 31961 at commit [`92deb16`](https://github.com/apache/spark/commit/92deb160ad92c69092a8dfa343a8f608680404c2).


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


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


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
##########
@@ -341,3 +341,53 @@ case class MultiplyDTInterval(
 
   override def toString: String = s"($left * $right)"
 }
+
+// Divide an year-month interval by a numeric
+case class DivideYMInterval(
+    interval: Expression,
+    num: Expression)
+  extends BinaryExpression with ImplicitCastInputTypes with NullIntolerant with Serializable {
+  override def left: Expression = interval
+  override def right: Expression = num
+
+  override def inputTypes: Seq[AbstractDataType] = Seq(YearMonthIntervalType, NumericType)
+  override def dataType: DataType = YearMonthIntervalType
+
+  @transient
+  private lazy val evalFunc: (Int, Any) => Any = right.dataType match {
+    case LongType => (months: Int, num) =>
+      LongMath.divide(months, num.asInstanceOf[Long], RoundingMode.HALF_UP).toInt

Review comment:
       It's better to put it as a code comment. We can fix it in the next PR.




-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


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


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   > Or should they be handled separately?
   
   @tanelk Separately. There is the JIRA https://issues.apache.org/jira/browse/SPARK-34841 for that. Need to add new expressions + 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:
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] yaooqinn commented on pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   late lgtm.


-- 
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 #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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


   @yaooqinn @cloud-fan Could you review 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