spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [spark] cloud-fan commented on a change in pull request #26256: [SPARK-29605][SQL] Optimize string to interval casting
Date Tue, 05 Nov 2019 12:13:07 GMT
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message