Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/11177#discussion_r52799617
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/Expand.scala ---
@@ -71,9 +80,76 @@ case class Expand(
idx = 0
}
+ numOutputRows += 1
result
}
}
}
}
+
+ override def upstream(): RDD[InternalRow] = {
+ child.asInstanceOf[CodegenSupport].upstream()
+ }
+
+ protected override def doProduce(ctx: CodegenContext): String = {
+ child.asInstanceOf[CodegenSupport].produce(ctx, this)
+ }
+
+ override def doConsume(ctx: CodegenContext, input: Seq[ExprCode]):
String = {
+ val uniqExprs: IndexedSeq[Set[Expression]] = output.indices.map { i =>
+ projections.map(p => p(i)).toSet
+ }
+
+ ctx.currentVars = input
+ val resultVars = uniqExprs.zipWithIndex.map { case (exprs, i) =>
+ val expr = exprs.head
+ if (exprs.size == 1) {
+ // it's common to have same expression for some columns in all the
projections, for example,
+ // GroupingSet will copy all the output from child as the first
part of output.
+ // We should only generate the columns once.
+ BindReferences.bindReference(expr, child.output).gen(ctx)
+ } else {
+ val isNull = ctx.freshName("isNull")
+ val value = ctx.freshName("value")
+ val code =
+ s"""
+ |boolean $isNull = true;
+ |${ctx.javaType(expr.dataType)} $value =
${ctx.defaultValue(expr.dataType)};
+ """.stripMargin
+ ExprCode(code, isNull, value)
+ }
+ }
+
+ // In order to prevent code exploration, we can't call `consume()`
many times, so we call
--- End diff --
The loop and copy two variables should only take about 1-2 nano second,
should not have regressions.
But if we don't have loop here, then the generated code could be much
easier to be larger than 8K, that could be regression (slower than without
codegen).
---
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]