Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19899#discussion_r155216344
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
---
@@ -602,23 +602,38 @@ case class Least(children: Seq[Expression]) extends
Expression {
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val evalChildren = children.map(_.genCode(ctx))
- ctx.addMutableState(ctx.JAVA_BOOLEAN, ev.isNull)
- ctx.addMutableState(ctx.javaType(dataType), ev.value)
- def updateEval(eval: ExprCode): String = {
+ val leastTmpIsNull = ctx.freshName("leastTmpIsNull")
+ ctx.addMutableState(ctx.JAVA_BOOLEAN, leastTmpIsNull)
+ val evals = evalChildren.map(eval =>
s"""
- ${eval.code}
- if (!${eval.isNull} && (${ev.isNull} ||
- ${ctx.genGreater(dataType, ev.value, eval.value)})) {
- ${ev.isNull} = false;
- ${ev.value} = ${eval.value};
- }
- """
- }
- val codes =
ctx.splitExpressionsWithCurrentInputs(evalChildren.map(updateEval))
- ev.copy(code = s"""
- ${ev.isNull} = true;
- ${ev.value} = ${ctx.defaultValue(dataType)};
- $codes""")
+ |${eval.code}
+ |if (!${eval.isNull} && (${leastTmpIsNull} ||
--- End diff --
nit `$leastTmpIsNull`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]