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_r344470744
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -1774,14 +1774,17 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
           val zoneId = getZoneId(SQLConf.get.sessionLocalTimeZone)
           toLiteral(stringToTimestamp(_, zoneId), TimestampType)
         case "INTERVAL" =>
-          val interval = try {
+          val intervalWithoutSign = try {
             IntervalUtils.fromString(value)
           } catch {
             case e: IllegalArgumentException =>
               val ex = new ParseException("Cannot parse the INTERVAL value: " 
+ value, ctx)
               ex.setStackTrace(e.getStackTrace)
               throw ex
           }
+          val interval = if (ctx.sign != null && ctx.sign.getText == "-") {
+            IntervalUtils.negate(intervalWithoutSign)
+          } else intervalWithoutSign
           Literal(interval, CalendarIntervalType)
 
 Review comment:
   We can use one line here and revert 1777 by reusing the generalized 
`applySign`.
   ```scala
   -          val interval = if (ctx.sign != null && ctx.sign.getText == "-") {
   -            IntervalUtils.negate(intervalWithoutSign)
   -          } else intervalWithoutSign
   -          Literal(interval, CalendarIntervalType)
   +          Literal(applySign(ctx.sign, interval), CalendarIntervalType)
   ```

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

Reply via email to