MaxGekk commented on a change in pull request #32056:
URL: https://github.com/apache/spark/pull/32056#discussion_r607626929



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -834,4 +834,21 @@ object IntervalUtils {
    * @return The period of months, not null
    */
   def monthsToPeriod(months: Int): Period = 
Period.ofMonths(months).normalized()
+
+  /**
+   * Converts an year-month interval as a number of months to its textual 
representation
+   * which conforms to the ANSI SQL standard.
+   *
+   * @param months The number of months, positive or negative
+   * @return Year-month interval string
+   */
+  def toYMIntervalString(months: Int): String = {
+    var sign = ""
+    var absMonths: Long = months
+    if (months < 0) {
+      sign = "-"
+      absMonths = -absMonths
+    }
+    s"interval '$sign${absMonths / MONTHS_PER_YEAR}-${absMonths % 
MONTHS_PER_YEAR}' year to month"

Review comment:
       Both are allowed by the standard. See the grammar rules:
   ```
   <unquoted interval string> ::=
   [ <sign> ] { <year-month literal> | <day-time literal> }
   ```
   ```
   <interval literal> ::=
     INTERVAL [ <sign> ] <interval string> <interval qualifier>
   ```




-- 
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:
[email protected]



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

Reply via email to