Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Literal(interval, CalendarIntervalType)
case "X" =>
val padding = if (value.length % 2 != 0) "0" else ""
Literal(DatatypeConverter.parseHexBinary(padding + value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ class ExpressionParserSuite extends AnalysisTest {
val intervalLiteral = Literal(CalendarInterval.fromString("interval 3 month 1 hour"))
assertEqual("InterVal 'interval 3 month 1 hour'", intervalLiteral)
assertEqual("INTERVAL '3 month 1 hour'", intervalLiteral)
assertEqual("Interval 'interval 3 monthsss 1 hoursss'",
Literal(null, CalendarIntervalType))
intercept("Interval 'interval 3 monthsss 1 hoursss'")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can refer to the timestamp/date tests just a few lines above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test suite defines the intercept method and uses it in many places. I don't want to break the rule here. It's definitely better to update the intercept method and take a error message parameter. This should be done in a followup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method has messages arg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn, the date and timestamp tests don't specify message, and I thought it doesn't have the message arg... Let me update it now.


// Binary.
assertEqual("X'A'", Literal(Array(0x0a).map(_.toByte)))
Expand Down