jackylee-ch commented on code in PR #47193: URL: https://github.com/apache/spark/pull/47193#discussion_r1663681759
########## sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUDFs.scala: ########## @@ -154,14 +154,18 @@ private[hive] case class HiveGenericUDF( val refEvaluator = ctx.addReferenceObj("evaluator", evaluator) val evals = children.map(_.genCode(ctx)) + val funcArg = ctx.freshName("funcArg") + val finalEval = ctx.freshName("finalEval") val setValues = evals.zipWithIndex.map { case (eval, i) => s""" - |if (${eval.isNull}) { - | $refEvaluator.setArg($i, null); - |} else { - | $refEvaluator.setArg($i, ${eval.value}); - |} + |final Object $finalEval = ${eval.isNull} ? null: ${eval.value}; + |scala.Function0<Object> $funcArg = new scala.Function0<Object>() { + | public Object apply() { + | return $finalEval; + | } + | }; + |$refEvaluator.setFuncArg($i, $funcArg); Review Comment: This won't work as we should mv the `eval.code` in apply, so that we can lazy run child functions. Just like the following code. ``` |$refEvaluator.setArg($i, new scala.runtime.AbstractFunction0<Object>() { | public Object apply() { | ${eval.code} | return ${eval.value}; | } |}); """.stripMargin ``` -- 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