maropu 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_r322000055
 
 

 ##########
 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:
   Naturally thinking from the comment, I thought the type's 
`mutable.HashMap.empty[StructuralExpr, mutable.ArrayBuffer[Expression]]`. Is  
the value `EquivalenceMap` because you reuse the existing logic?

----------------------------------------------------------------
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

Reply via email to