LuciferYang commented on code in PR #50236: URL: https://github.com/apache/spark/pull/50236#discussion_r1991323757
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala: ########## @@ -1337,6 +1350,35 @@ case class Cast( } } + private[this] def castToTimeCode( + from: DataType, + ctx: CodegenContext): CastFunction = { + from match { + case _: StringType => + val longOpt = ctx.freshVariable("longOpt", classOf[Option[Long]]) + (c, evPrim, evNull) => + if (ansiEnabled) { + val errorContext = getContextOrNullCode(ctx) + code""" + $evPrim = $dateTimeUtilsCls.stringToTimeAnsi($c, $errorContext); + """ + } else { + code""" + scala.Option<Long> $longOpt = + org.apache.spark.sql.catalyst.util.DateTimeUtils.stringToTime($c); Review Comment: Can also use `$dateTimeUtilsCls.stringToTime($c);` ? ########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala: ########## @@ -1337,6 +1350,35 @@ case class Cast( } } + private[this] def castToTimeCode( + from: DataType, + ctx: CodegenContext): CastFunction = { + from match { + case _: StringType => + val longOpt = ctx.freshVariable("longOpt", classOf[Option[Long]]) + (c, evPrim, evNull) => + if (ansiEnabled) { + val errorContext = getContextOrNullCode(ctx) + code""" + $evPrim = $dateTimeUtilsCls.stringToTimeAnsi($c, $errorContext); + """ + } else { + code""" + scala.Option<Long> $longOpt = + org.apache.spark.sql.catalyst.util.DateTimeUtils.stringToTime($c); + if ($longOpt.isDefined()) { + $evPrim = ((Long) $longOpt.get()).longValue(); + } else { + $evNull = true; + } + """ + } + + case _ => + (_, evPrim, evNull) => code"$evNull = true;" Review Comment: ```suggestion (_, _, evNull) => code"$evNull = true;" ``` -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org