Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19728#discussion_r150468020
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
---
@@ -63,15 +63,28 @@ case class Concat(children: Seq[Expression]) extends
Expression with ImplicitCas
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = {
val evals = children.map(_.genCode(ctx))
- val inputs = evals.map { eval =>
- s"${eval.isNull} ? null : ${eval.value}"
- }.mkString(", ")
- ev.copy(evals.map(_.code).mkString("\n") + s"""
- boolean ${ev.isNull} = false;
- UTF8String ${ev.value} = UTF8String.concat($inputs);
- if (${ev.value} == null) {
- ${ev.isNull} = true;
+ val argNums = evals.length
+ val args = ctx.freshName("argLen")
+ ctx.addMutableState("UTF8String[]", args, "")
+
+ val inputs = evals.zipWithIndex.map { case (eval, index) =>
+ if (eval.isNull != "true") {
+ s"""
+ ${eval.code}
+ if (!${eval.isNull}) {
+ $args[$index] = ${eval.value};
+ }
--- End diff --
That is guaranteed before the first row processed. After we process rows,
`args` are updated for each row. E.g., `args[0]` can be updated and assigned
with a string for row 0. In next row, if `eval.isNull` is evaluated to true, we
don't override back to null, so `arg[0]` is still the string value for row 0.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]