dongjoon-hyun commented on a change in pull request #26438: [SPARK-29408][SQL]
Support sign before `interval` in interval literals
URL: https://github.com/apache/spark/pull/26438#discussion_r344470714
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
##########
@@ -1932,14 +1935,22 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
* - from-to unit, for instance: interval '1-2' year to month.
*/
override def visitInterval(ctx: IntervalContext): Literal = withOrigin(ctx) {
+ def applySign(interval: CalendarInterval): CalendarInterval = {
+ if (ctx.sign != null && ctx.sign.getText == "-") {
+ IntervalUtils.negate(interval)
+ } else {
+ interval
+ }
+ }
if (ctx.errorCapturingMultiUnitsInterval != null) {
val innerCtx = ctx.errorCapturingMultiUnitsInterval
if (innerCtx.unitToUnitInterval != null) {
throw new ParseException(
"Can only have a single from-to unit in the interval literal syntax",
innerCtx.unitToUnitInterval)
}
- Literal(visitMultiUnitsInterval(innerCtx.multiUnitsInterval),
CalendarIntervalType)
+ val interval =
applySign(visitMultiUnitsInterval(innerCtx.multiUnitsInterval))
Review comment:
```scala
- val interval =
applySign(visitMultiUnitsInterval(innerCtx.multiUnitsInterval))
+ val interval = applySign(ctx.sign,
visitMultiUnitsInterval(innerCtx.multiUnitsInterval))
```
----------------------------------------------------------------
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]