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

    https://github.com/apache/spark/pull/19797#discussion_r152712011
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ---
    @@ -851,9 +855,11 @@ case class Cast(child: Expression, dataType: DataType, 
timeZoneId: Option[String
     
       private[this] def castToIntCode(from: DataType, ctx: CodegenContext): 
CastFunction = from match {
         case StringType =>
    -      val wrapper = ctx.freshName("wrapper")
    -      ctx.addMutableState("UTF8String.IntWrapper", wrapper,
    -        s"$wrapper = new UTF8String.IntWrapper();")
    +      val wrapper = "intWrapper"
    +      if (!ctx.mutableStates.exists(s => s._1 == wrapper)) {
    +        ctx.addMutableState("UTF8String.IntWrapper", wrapper,
    +          s"$wrapper = new UTF8String.IntWrapper();")
    +      }
           (c, evPrim, evNull) =>
             s"""
               if ($c.toInt($wrapper)) {
    --- End diff --
    
    It would work well, too. We may have some overhead to create a small object 
`IntWrapper` and collect it at GC.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to