Peng-Lei commented on a change in pull request #34494:
URL: https://github.com/apache/spark/pull/34494#discussion_r751040338



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -1253,4 +1255,120 @@ object IntervalUtils {
     }
     intervalString
   }
+
+  def intToYearMonthInterval(v: Int, endField: Byte): Int = {
+    endField match {
+      case YEAR =>
+        try {
+          Math.multiplyExact(v, MONTHS_PER_YEAR)
+        } catch {
+          case _: ArithmeticException =>
+            throw QueryExecutionErrors.castingCauseOverflowError(v, 
YM(endField).catalogString)
+        }
+      case MONTH => v
+    }
+  }
+
+  def longToYearMonthInterval(v: Long, endField: Byte): Int = {
+    val vInt = v.toInt
+    if (v != vInt) {
+      throw QueryExecutionErrors.castingCauseOverflowError(v, 
YM(endField).catalogString)
+    }
+    intToYearMonthInterval(vInt, endField)
+  }
+
+  def yearMonthIntervalToInt(v: Int, startField: Byte, endField: Byte): Int = {

Review comment:
       Here, startField is not used. but in order to unify code in codegen 
`$evPrim = $util.yearMonthIntervalTo$integralType($c, (byte)$startField, 
(byte)$endField);`.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to