Github user yjshen commented on a diff in the pull request:
https://github.com/apache/spark/pull/8353#discussion_r37693607
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala
---
@@ -114,8 +114,44 @@ case class ConcatWs(children: Seq[Expression])
boolean ${ev.isNull} = ${ev.primitive} == null;
"""
} else {
- // Contains a mix of strings and array<string>s. Fall back to
interpreted mode for now.
- super.genCode(ctx, ev)
+ val array = ctx.freshName("array")
+ val varargNum = ctx.freshName("varargNum")
+ val idxInVararg = ctx.freshName("idxInVararg")
+
+ val evals = children.map(_.gen(ctx))
+ val (varargCount, varargBuild) = children.tail.zip(evals.tail).map {
case (child, eval) =>
+ child.dataType match {
+ case StringType =>
+ (s"$varargNum ++;",
+ s"$array[$idxInVararg ++] = ${eval.isNull} ? (UTF8String)
null : ${eval.primitive};")
+ case _: ArrayType =>
+ val size = ctx.freshName("n")
+ (s"""
+ if (!${eval.isNull}) {
+ $varargNum += ${eval.primitive}.numElements();
+ }
+ """,
+ s"""
+ if (!${eval.isNull}) {
+ final int $size = ${eval.primitive}.numElements();
+ for (int j = 0; j < $size; j ++) {
+ $array[$idxInVararg ++] = ${ctx.getValue(eval.primitive,
StringType, "j")};
+ }
+ }
+ """)
+ }
+ }.unzip
+
+ evals.map(_.code).mkString("\n") +
+ s"""
+ int $varargNum = 0;
--- End diff --
@davies , more comments on this PR?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]