cloud-fan commented on a change in pull request #33142:
URL: https://github.com/apache/spark/pull/33142#discussion_r660897248
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala
##########
@@ -93,25 +72,36 @@ class EquivalentExpressions {
*/
private def addCommonExprs(
exprs: Seq[Expression],
- addFunc: Expression => Boolean = addExpr): Unit = {
- val exprSetForAll = mutable.Set[Expr]()
- addExprTree(exprs.head, addExprToSet(_, exprSetForAll))
-
- val candidateExprs = exprs.tail.foldLeft(exprSetForAll) { (exprSet, expr)
=>
- val otherExprSet = mutable.Set[Expr]()
- addExprTree(expr, addExprToSet(_, otherExprSet))
- exprSet.intersect(otherExprSet)
+ map: mutable.HashMap[ExpressionEquals, ExpressionStats]): Unit = {
+ assert(exprs.length > 1)
+ var localEquivalenceMap = mutable.HashMap.empty[ExpressionEquals,
ExpressionStats]
+ addExprTree0(exprs.head, localEquivalenceMap)
+
+ exprs.tail.foreach { expr =>
+ val otherLocalEquivalenceMap = mutable.HashMap.empty[ExpressionEquals,
ExpressionStats]
+ addExprTree0(expr, otherLocalEquivalenceMap)
+ localEquivalenceMap = localEquivalenceMap.filter { case (key, _) =>
+ otherLocalEquivalenceMap.contains(key)
+ }
}
- // Not all expressions in the set should be added. We should filter out
the related
- // children nodes.
- val commonExprSet = candidateExprs.filter { candidateExpr =>
- candidateExprs.forall { expr =>
- expr == candidateExpr ||
expr.e.find(_.semanticEquals(candidateExpr.e)).isEmpty
+ localEquivalenceMap.foreach { case (commonExpr, state) =>
+ val possibleParents = localEquivalenceMap.filter { case (_, v) =>
v.height > state.height }
Review comment:
This partially solves the perf issue mentioned in
https://github.com/apache/spark/pull/32559/files#r633488455
By filtering with height first, we can reduce the data to iterate.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]