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



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -2452,9 +2491,16 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with 
SQLConfHelper with Logg
           } else {
             values(i).getText
           }
+
           UTF8String.fromString(" " + v + " " + u)
         }
-        IntervalUtils.stringToInterval(UTF8String.concat(kvs: _*))
+        val intervalLiteral = UTF8String.concat(kvs: _*)
+        val calendarInterval = IntervalUtils.stringToInterval(intervalLiteral)
+        if (!conf.legacyIntervalEnabled && isYearMonthInterval && 
isDayTimeInterval) {
+          throw 
QueryParsingErrors.mixedIntervalUnitsError(intervalLiteral.toString.trim, ctx)

Review comment:
       Yes. it's to give users error message with literal which is easy to 
understand, as you 
[suggested](https://github.com/apache/spark/pull/32949#discussion_r664724125).
   The assertion added is not for users but to detect a kind of bug.
   `visitInterval` implicitly relies on the premise that 
`visitMultiUnitsInterval` is called and detect mixed fields.
   So, if someone changes code around `visitInterval` in the future, the 
premise may not hold.
   To detect such a case, I placed that assertion.

##########
File path: sql/core/src/test/resources/sql-tests/inputs/cast.sql
##########
@@ -58,8 +58,10 @@ DESC FUNCTION EXTENDED boolean;
 -- TODO: migrate all cast tests here.
 
 -- cast string to interval and interval to string
-SELECT CAST('interval 3 month 1 hour' AS interval);

Review comment:
       It's already restored.
   
https://github.com/apache/spark/pull/32949/files#diff-074fea4985c405ca07b5319bdcb9b550a2b1275d776cab2e61b7e3042a64f47eL61




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