wangyum commented on a change in pull request #26151: [SPARK-29502][SQL] typed
interval expression should fail for invalid format
URL: https://github.com/apache/spark/pull/26151#discussion_r336310876
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -1769,7 +1769,15 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
val zoneId = getZoneId(SQLConf.get.sessionLocalTimeZone)
toLiteral(stringToTimestamp(_, zoneId), TimestampType)
case "INTERVAL" =>
- Literal(CalendarInterval.fromString(value), CalendarIntervalType)
+ val interval = try {
+ CalendarInterval.fromCaseInsensitiveString(value)
+ } catch {
+ case e: IllegalArgumentException =>
+ val ex = new ParseException(e.getMessage, ctx)
+ ex.setStackTrace(e.getStackTrace)
+ throw ex
+ }
Review comment:
The error message is still inconsistent. `Invalid interval` vs `Cannot parse
the DATE value`:
```
scala> spark.sql("select Interval '10000 secondss'").show(false)
org.apache.spark.sql.catalyst.parser.ParseException:
Invalid interval: 10000 secondss(line 1, pos 7)
```
```
scala> spark.sql("select date '10000 secondss'").show(false)
org.apache.spark.sql.catalyst.parser.ParseException:
Cannot parse the DATE value: 10000 secondss(line 1, pos 7)
== SQL ==
select date '10000 secondss'
-------^^^
```
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]