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

    https://github.com/apache/spark/pull/21193#discussion_r187033550
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ---
    @@ -623,8 +624,14 @@ case class Cast(child: Expression, dataType: DataType, 
timeZoneId: Option[String
       override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
         val eval = child.genCode(ctx)
         val nullSafeCast = nullSafeCastFunction(child.dataType, dataType, ctx)
    +
    +    // Below the code comment including `eval.value` and `eval.isNull` is 
a trick. It makes the two
    +    // expr values are referred by this code block.
         ev.copy(code = eval.code +
    -      castCode(ctx, eval.value, eval.isNull, ev.value, ev.isNull, 
dataType, nullSafeCast))
    +      code"""
    +        // Cast from ${eval.value}, ${eval.isNull}
    +        ${castCode(ctx, eval.value, eval.isNull, ev.value, ev.isNull, 
dataType, nullSafeCast)}
    --- End diff --
    
    We can use `ExprValue` and `Block` around everywhere in `Cast` here (I did 
in a local branch), just it increases some code diff, so I'm not sure if we 
want it be here or as a follow-up if it's easier for review.
    
    Inputs to `Cast` should be only `eval.value` and `eval.isNull` as it's only 
child expression to `Cast`. We add generated codes here but they are not 
actually input expressions to `Cast`. So for now I manually let `eval.value` 
and `eval.isNull` be tracked.
    
    



---

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

Reply via email to