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

    https://github.com/apache/spark/pull/19891#discussion_r154999955
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ---
    @@ -1024,37 +1024,33 @@ case class Cast(child: Expression, dataType: 
DataType, timeZoneId: Option[String
           val toFieldNull = ctx.freshName("tfn")
           val fromType = ctx.javaType(from.fields(i).dataType)
           s"""
    -        boolean $fromFieldNull = $tmpRow.isNullAt($i);
    +        boolean $fromFieldNull = $tmpInput.isNullAt($i);
             if ($fromFieldNull) {
    -          $result.setNullAt($i);
    +          $tmpResult.setNullAt($i);
             } else {
               $fromType $fromFieldPrim =
    -            ${ctx.getValue(tmpRow, from.fields(i).dataType, i.toString)};
    +            ${ctx.getValue(tmpInput, from.fields(i).dataType, i.toString)};
               ${castCode(ctx, fromFieldPrim,
                 fromFieldNull, toFieldPrim, toFieldNull, 
to.fields(i).dataType, cast)}
               if ($toFieldNull) {
    -            $result.setNullAt($i);
    +            $tmpResult.setNullAt($i);
               } else {
    -            ${ctx.setColumn(result, to.fields(i).dataType, i, 
toFieldPrim)};
    +            ${ctx.setColumn(tmpResult, to.fields(i).dataType, i, 
toFieldPrim)};
               }
             }
            """
         }
    -    val fieldsEvalCodes = if (ctx.currentVars == null) {
    -      ctx.splitExpressions(
    -        expressions = fieldsEvalCode,
    -        funcName = "castStruct",
    -        arguments = ("InternalRow", tmpRow) :: (rowClass, result) :: Nil)
    -    } else {
    -      fieldsEvalCode.mkString("\n")
    -    }
    +    val fieldsEvalCodes = ctx.splitExpressions(
    +      expressions = fieldsEvalCode,
    +      funcName = "castStruct",
    +      arguments = ("InternalRow", tmpInput) :: (rowClass, tmpResult) :: 
Nil)
     
    -    (c, evPrim, evNull) =>
    +    (input, result, resultIsNull) =>
           s"""
    -        final $rowClass $result = new $rowClass(${fieldsCasts.length});
    -        final InternalRow $tmpRow = $c;
    +        final $rowClass $tmpResult = new $rowClass(${fieldsCasts.length});
    +        final InternalRow $tmpInput = $input;
    --- End diff --
    
    oh, now I see! Thanks for the kind explanation.


---

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

Reply via email to