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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalUtils.scala
##########
@@ -93,6 +93,24 @@ object IntervalUtils {
 
   private val yearMonthPattern = "^([+|-])?(\\d+)-(\\d+)$".r
 
+  def safeFromYearMonthString(input: UTF8String): Option[Int] = {
+    try {
+      if (input == null || input.toString == null) {
+        throw new IllegalArgumentException("Interval year-month string must be 
not null")
+      } else {
+        val regex = "INTERVAL '([-|+]?[0-9]+-[-|+]?[0-9]+)' YEAR TO MONTH".r

Review comment:
       First of all, we must support our own output (in case insensitive manner 
by default but ideally we should respect the SQL config 
`spark.sql.caseSensitive`):
   1. ANSI_STYLE, like
   INTERVAL -'-10-1' YEAR TO MONTH
   2. HIVE_STYLE like
   10-1 or -10-1
   
   Rules from the SQL standard:
   ```
   <interval literal> ::=
     INTERVAL [ <sign> ] <interval string> <interval qualifier>
   <interval string> ::=
     <quote> <unquoted interval string> <quote>
   <unquoted interval string> ::=
     [ <sign> ] { <year-month literal> | <day-time literal> }
   <year-month literal> ::=
     <years value> [ <minus sign> <months value> ]
     | <months value>
   <years value> ::=
     <datetime value>
   <months value> ::=
     <datetime value>
   <datetime value> ::=
     <unsigned integer>
   <unsigned integer> ::= <digit>...
   ```




-- 
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to