viirya commented on a change in pull request #25717: [WIP][SPARK-29013][SQL] Structurally equivalent subexpression elimination URL: https://github.com/apache/spark/pull/25717#discussion_r322027230
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/EquivalentExpressions.scala ########## @@ -40,23 +40,47 @@ class EquivalentExpressions { override def hashCode: Int = e.semanticHash() } + /** + * Wrapper around an Expression that provides structural semantic equality. + */ + case class StructuralExpr(e: Expression) { + def normalized(expr: Expression): Expression = { + expr.transformUp { + case b: ParameterizedBoundReference => + b.copy(parameter = "") + } + } + override def equals(o: Any): Boolean = o match { + case other: StructuralExpr => + normalized(e).semanticEquals(normalized(other.e)) + case _ => false + } + + override def hashCode: Int = normalized(e).semanticHash() + } + + type EquivalenceMap = mutable.HashMap[Expr, mutable.ArrayBuffer[Expression]] + // For each expression, the set of equivalent expressions. private val equivalenceMap = mutable.HashMap.empty[Expr, mutable.ArrayBuffer[Expression]] + // For each expression, the set of structurally equivalent expressions. + private val structEquivalenceMap = mutable.HashMap.empty[StructuralExpr, EquivalenceMap] Review comment: Among expressions with same structure, there are still different sub-set of expressions which are semantically different to each others. I need the EquivalenceMap here to distinguish them. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org