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



##########
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 `1`, I've fixed in this PR.
   For `2`, it's about intervals, not timestamps so we don't need to consider 
daylight saving here right?




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