cloud-fan commented on a change in pull request #34494:
URL: https://github.com/apache/spark/pull/34494#discussion_r750879209
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -1253,4 +1255,115 @@ 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, endFiled: Byte): Int = {
+ endFiled match {
+ case YEAR => v / MONTHS_PER_YEAR
+ case MONTH => v
+ }
+ }
+
+ def yearMonthIntervalToShort(v: Int, endFiled: Byte): Short = {
+ val vInt = yearMonthIntervalToInt(v, endFiled)
+ val vShort = vInt.toShort
+ if (vInt != vShort) {
+ throw QueryExecutionErrors.castingCauseOverflowError(v,
ShortType.catalogString);
Review comment:
not a blocker, but it will be great to print `v` with interval format,
not just an integer.
--
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]