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 19:29:25 UTC

[GitHub] [spark] MaxGekk commented on a change in pull request #31961: [SPARK-34868][SQL] Support divide an year-month interval by a numeric

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