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



##########
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:
       O.K, let's fix this in this PR.

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

Review comment:
       At first I tried to put a common helper function but they are slightly 
different so I didn't.
   But it's O.K, to try to factor out the similar code.

##########
File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/TimeWindowSuite.scala
##########
@@ -21,10 +21,10 @@ import org.scalatest.PrivateMethodTester
 
 import org.apache.spark.SparkFunSuite
 import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.util.DateTimeConstants._
 import org.apache.spark.sql.types.{LongType, StructField, StructType, 
TimestampNTZType, TimestampType}
 
 class TimeWindowSuite extends SparkFunSuite with ExpressionEvalHelper with 
PrivateMethodTester {
-

Review comment:
       Oops. Thanks.




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