Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19964#discussion_r156685309
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
---
@@ -289,53 +289,56 @@ case class Elt(children: Seq[Expression])
val index = indexExpr.genCode(ctx)
val strings = stringExprs.map(_.genCode(ctx))
val indexVal = ctx.freshName("index")
+ val indexMatched = ctx.freshName("eltIndexMatched")
+
val stringVal = ctx.freshName("stringVal")
+ ctx.addMutableState(ctx.javaType(dataType), stringVal)
+
val assignStringValue = strings.zipWithIndex.map { case (eval, index)
=>
s"""
- case ${index + 1}:
- ${eval.code}
- $stringVal = ${eval.isNull} ? null : ${eval.value};
- break;
- """
+ |if ($indexVal == ${index + 1}) {
+ | ${eval.code}
+ | $stringVal = ${eval.isNull} ? null : ${eval.value};
+ | $indexMatched = true;
+ | continue;
+ |}
+ """.stripMargin
}
- val cases = ctx.buildCodeBlocks(assignStringValue)
--- End diff --
now `ctx.buildCodeBlock` doesn't need to be a separate method, can we
revert that change and inline `buildCodeBlock` to `splitExpressions`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]