MaxGekk commented on a change in pull request #26285: [SPARK-29623][SQL] do not
allow multiple unit TO unit statements in interval literal syntax
URL: https://github.com/apache/spark/pull/26285#discussion_r340147529
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -1929,72 +1916,98 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
}
}
- /**
- * Create a [[CalendarInterval]] literal expression. An interval expression
can contain multiple
- * unit value pairs, for instance: interval 2 months 2 days.
- */
override def visitInterval(ctx: IntervalContext): Literal = withOrigin(ctx) {
- val intervals = ctx.intervalField.asScala.map(visitIntervalField)
- validate(intervals.nonEmpty, "at least one time unit should be given for
interval literal", ctx)
- Literal(intervals.reduce(_.add(_)))
+ if (ctx.errorCapturingMultiUnitsInterval != null) {
+ val innerCtx = ctx.errorCapturingMultiUnitsInterval
+ if (innerCtx.unitToUnitInterval != null) {
+ throw new ParseException(
+ "Can only have a single unit TO unit statement in the interval
literal syntax",
+ innerCtx.unitToUnitInterval)
+ }
+ Literal(visitMultiUnitsInterval(innerCtx.multiUnitsInterval))
Review comment:
Could you specify `CalendarIntervalType` to avoid unnecessary pattern
matching for inferring the type by provided value.
----------------------------------------------------------------
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]