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 2022/08/12 10:35:15 UTC

[GitHub] [spark] cloud-fan commented on a diff in pull request #37466: [SPARK-40014][SQL] Support cast of decimals to ANSI intervals

cloud-fan commented on code in PR #37466:
URL: https://github.com/apache/spark/pull/37466#discussion_r944334882


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala:
##########
@@ -1283,6 +1283,20 @@ object IntervalUtils {
     intToYearMonthInterval(vInt, startField, endField)
   }
 
+  def decimalToYearMonthInterval(
+      d: Decimal, p: Int, s: Int, startField: Byte, endField: Byte): Int = {
+    try {
+      val months = if (endField == YEAR) d.toBigDecimal * MONTHS_PER_YEAR else d.toBigDecimal
+      months.setScale(0, BigDecimal.RoundingMode.HALF_UP).toIntExact

Review Comment:
   do we have a sql reference doc for cast? we should mention the rounding behavior.



-- 
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: reviews-unsubscribe@spark.apache.org

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