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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/TimeWindow.scala
##########
@@ -110,10 +115,26 @@ object TimeWindow {
    *         precision.
    */
   def getIntervalInMicroSeconds(interval: String): Long = {
-    val cal = IntervalUtils.stringToInterval(UTF8String.fromString(interval))
-    if (cal.months != 0) {
-      throw new IllegalArgumentException(
-        s"Intervals greater than a month is not supported ($interval).")
+    val ymIntervalErrMsg = s"Intervals greater than a month is not supported 
($interval)."
+    val cal = try {
+      if (interval.toLowerCase(Locale.ROOT).trim.startsWith("interval")) {
+        CatalystSqlParser.parseExpression(interval) match {
+          case Literal(_: Int, _: YearMonthIntervalType) =>
+            throw new IllegalArgumentException(ymIntervalErrMsg)
+          case Literal(micros: Long, _: DayTimeIntervalType) =>
+            new CalendarInterval(0, 0, micros)
+        }
+      } else {
+        val parsed = 
IntervalUtils.stringToInterval(UTF8String.fromString(interval))
+        if (parsed.months != 0) {
+          throw new IllegalArgumentException(ymIntervalErrMsg)
+        } else {
+          parsed
+        }
+      }
+    } catch {
+      case NonFatal(e) =>
+        throw QueryCompilationErrors.cannotParseTimeDelayError(interval, e)
     }
     cal.days * MICROS_PER_DAY + cal.microseconds

Review comment:
       > For 2, it's about intervals, not timestamps so we don't need to 
consider daylight saving here right?
   
   ok. Let's keep the assumption of 24 hours per day here. Not sure it will 
work fine during daylight saving time but it seems we don't have enough test 
coverage for that at the moment.
   
   Maybe, open an JIRA to test the case?




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

Reply via email to