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_r344470684
 
 

 ##########
 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
+      }
+    }
 
 Review comment:
   Shall we make this function more reusable and move outside of 
`visitInterval`?
   ```scala
     private def applySign(sign: Token, interval: CalendarInterval): 
CalendarInterval = {
       if (sign != null && sign.getText == "-") {
         IntervalUtils.negate(interval)
       } else {
         interval
       }
     }
   ```

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