viirya commented on a change in pull request #25717: [SPARK-29013][SQL]
Structurally equivalent subexpression elimination
URL: https://github.com/apache/spark/pull/25717#discussion_r324431148
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
##########
@@ -1050,11 +1056,100 @@ class CodegenContext {
}
/**
- * Checks and sets up the state and codegen for subexpression elimination.
This finds the
- * common subexpressions, generates the functions that evaluate those
expressions and populates
- * the mapping of common subexpressions to the generated functions.
- */
- private def subexpressionElimination(expressions: Seq[Expression]): Unit = {
+ * This is for sub-expression elimination targeting structurally equivalent
expressions.
+ * This is only supported in non whole-stage codegen.
+ *
+ * Two expressions are structurally equivalent if they are the same except
for the individual
+ * input slot in current processing row (i.e., `INPUT_ROW`).
+ *
+ * For example, expression a is input[1] + input[2], expression b is
input[3] + input[4]. They
+ * are not semantically equivalent in SparkSQL, but they have the same
computation on different
+ * input data.
+ *
+ * This method generates a common function for a set of structurally
equivalent expressions.
+ * Among the set, the expressions with same semantics are replaced with a
function call to the
+ * generated function, by passing in input slots of current processing row.
+ */
+ private def structuralSubexpressionElimination(expressions:
Seq[Expression]): Seq[Expression] = {
+ // Add each expression tree and compute the structurally common
subexpressions.
+ // Those expressions are not added into structurally common
subexpressions, defer them to
+ // semantically common subexpression.
+ val exprsOut =
Review comment:
ok.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]