Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21537#discussion_r195331403
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ---
    @@ -805,43 +811,43 @@ case class Cast(child: Expression, dataType: 
DataType, timeZoneId: Option[String
       private[this] def castToStringCode(from: DataType, ctx: CodegenContext): 
CastFunction = {
         from match {
           case BinaryType =>
    -        (c, evPrim, evNull) => s"$evPrim = UTF8String.fromBytes($c);"
    +        (c, evPrim, evNull) => code"$evPrim = UTF8String.fromBytes($c);"
           case DateType =>
    -        (c, evPrim, evNull) => s"""$evPrim = UTF8String.fromString(
    +        (c, evPrim, evNull) => code"""$evPrim = UTF8String.fromString(
               
org.apache.spark.sql.catalyst.util.DateTimeUtils.dateToString($c));"""
           case TimestampType =>
    -        val tz = ctx.addReferenceObj("timeZone", timeZone)
    -        (c, evPrim, evNull) => s"""$evPrim = UTF8String.fromString(
    +        val tz = JavaCode.global(ctx.addReferenceObj("timeZone", 
timeZone), timeZone.getClass)
    +        (c, evPrim, evNull) => code"""$evPrim = UTF8String.fromString(
               
org.apache.spark.sql.catalyst.util.DateTimeUtils.timestampToString($c, $tz));"""
           case ArrayType(et, _) =>
             (c, evPrim, evNull) => {
    -          val buffer = ctx.freshName("buffer")
    -          val bufferClass = classOf[UTF8StringBuilder].getName
    +          val buffer = ctx.freshVariable("buffer", 
classOf[UTF8StringBuilder])
    +          val bufferClass = JavaCode.className(classOf[UTF8StringBuilder])
    --- End diff --
    
    Now, each variable defined by `freshVariable` has a type. We can get a type 
or its class name from the variable (e.g. `bufffer`). Therefore, it looks 
redundant to declare a name of each variable again (e.g. bufferClass).
    Do we have an API to get a type of the variable or define an API to get a 
name of the class? This is because this pattern is very common.


---

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

Reply via email to