Github user nongli commented on a diff in the pull request:
https://github.com/apache/spark/pull/11403#discussion_r55105893
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala
---
@@ -237,4 +237,65 @@ abstract class QueryPlan[PlanType <:
TreeNode[PlanType]] extends TreeNode[PlanTy
}
override def innerChildren: Seq[PlanType] = subqueries
+
+ /**
+ * Cleaned copy of this query plan.
+ */
+ protected lazy val cleaned: PlanType = this
+
+ /**
+ * Returns true when the given query plan will return the same results
as this query plan.
+ *
+ * Since its likely undecidable to generally determine if two given
plans will produce the same
+ * results, it is okay for this function to return false, even if the
results are actually
+ * the same. Such behavior will not affect correctness, only the
application of performance
+ * enhancements like caching. However, it is not acceptable to return
true if the results could
+ * possibly be different.
+ *
+ * By default this function performs a modified version of equality that
is tolerant of cosmetic
+ * differences like attribute naming and or expression id differences.
Operators that
+ * can do better should override this function.
+ */
+ def sameResult(plan: PlanType): Boolean = {
+ val cleanLeft = this.cleaned
+ val cleanRight = plan.cleaned
+ cleanLeft.getClass == cleanRight.getClass &&
+ cleanLeft.children.size == cleanRight.children.size &&
+ cleanLeft.cleanArgs == cleanRight.cleanArgs &&
+ (cleanLeft.children, cleanRight.children).zipped.forall(_ sameResult
_)
+ }
+
+ /**
+ * All the attributes that are used for this plan.
+ */
+ lazy val allAttributes: Seq[Attribute] = children.flatMap(_.output)
+
+ private def cleanExpression(e: Expression): Expression = e match {
--- End diff --
How is this related to semantic equals?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]