MaxGekk commented on a change in pull request #26190: [SPARK-29532][SQL] 
simplify interval string parsing
URL: https://github.com/apache/spark/pull/26190#discussion_r336934290
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
 ##########
 @@ -100,6 +101,15 @@ class AstBuilder(conf: SQLConf) extends 
SqlBaseBaseVisitor[AnyRef] with Logging
     withOrigin(ctx)(StructType(visitColTypeList(ctx.colTypeList)))
   }
 
+  override def visitSingleInterval(ctx: SingleIntervalContext): 
CalendarInterval = {
+    withOrigin(ctx) {
+      val intervals = ctx.intervalField.asScala.map(visitIntervalField)
+      validate(intervals.nonEmpty,
+        "at least one time unit should be given for interval literal", ctx)
+      intervals.reduce(_.add(_))
 
 Review comment:
   You create an instance of `CalendarInterval` per each interval units, and 
always have to summarize months and microseconds  (and maybe days in the 
future), and create new instance per each `add()`?
   
   Let's benchmark this and see how it is fast.

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