You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/05/31 07:03:28 UTC
[GitHub] [spark] cloud-fan commented on a change in pull request #32699: [SPARK-35560][SQL] Remove redundant subexpression evaluation in nested subexpressions
cloud-fan commented on a change in pull request #32699:
URL: https://github.com/apache/spark/pull/32699#discussion_r642258116
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
##########
@@ -1039,21 +1039,25 @@ class CodegenContext extends Logging {
def subexpressionEliminationForWholeStageCodegen(expressions: Seq[Expression]): SubExprCodes = {
// Create a clear EquivalentExpressions and SubExprEliminationState mapping
val equivalentExpressions: EquivalentExpressions = new EquivalentExpressions
- val localSubExprEliminationExprs = mutable.HashMap.empty[Expression, SubExprEliminationState]
+ val localSubExprEliminationExprsForNonSplit =
+ mutable.HashMap.empty[Expression, SubExprEliminationState]
// Add each expression tree and compute the common subexpressions.
expressions.foreach(equivalentExpressions.addExprTree(_))
// Get all the expressions that appear at least twice and set up the state for subexpression
// elimination.
val commonExprs = equivalentExpressions.getAllEquivalentExprs(1)
- lazy val commonExprVals = commonExprs.map(_.head.genCode(this))
- lazy val nonSplitExprCode = {
- commonExprs.zip(commonExprVals).map { case (exprs, eval) =>
- // Generate the code for this expression tree.
- val state = SubExprEliminationState(eval.isNull, eval.value)
- exprs.foreach(localSubExprEliminationExprs.put(_, state))
+ val nonSplitExprCode = {
+ commonExprs.map { exprs =>
+ val eval = withSubExprEliminationExprs(localSubExprEliminationExprsForNonSplit.toMap) {
Review comment:
what does this recursive call of `withSubExprEliminationExprs` give us?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org