cloud-fan commented on a change in pull request #26256: [SPARK-29605][SQL] Optimize string to interval casting URL: https://github.com/apache/spark/pull/26256#discussion_r342529943
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala ########## @@ -1211,15 +1211,23 @@ abstract class CastBase extends UnaryExpression with TimeZoneAwareExpression wit """ } - private[this] def castToIntervalCode(from: DataType): CastFunction = from match { + private[this] def castToIntervalCode( + from: DataType, + ctx: CodegenContext): CastFunction = from match { case StringType => val util = IntervalUtils.getClass.getCanonicalName.stripSuffix("$") + val calOpt = ctx.freshVariable("calOpt", classOf[Option[CalendarInterval]]) + (c, evPrim, evNull) => - code"""$evPrim = $util.safeFromString($c.toString()); - if(${evPrim} == null) { - ${evNull} = true; - } - """.stripMargin + code""" + scala.Option<org.apache.spark.unsafe.types.CalendarInterval> $calOpt = Review comment: if it's used in codegen, I think it's more natural to return null instead of None. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org