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 11:22:35 UTC

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

MaxGekk commented on code in PR #37466:
URL: https://github.com/apache/spark/pull/37466#discussion_r944369423


##########
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:
   We have the doc for cast: https://spark.apache.org/docs/latest/sql-ref-ansi-compliance.html#cast but it says that Spark doesn't support cast of intervals to numerics. Let me open a PR and document recent changes in casting of ANSI intervals.



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