viirya commented on a change in pull request #31656:
URL: https://github.com/apache/spark/pull/31656#discussion_r584496283
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -526,21 +527,29 @@ object RemoveNoopUnion extends Rule[LogicalPlan] {
case _ => plan
}
- private def removeUnion(u: Union): Option[LogicalPlan] = {
- val unionChildren = u.children.map(removeAliasOnlyProject)
- if (unionChildren.tail.forall(unionChildren.head.sameResult(_))) {
- Some(u.children.head)
+ private def simplifyUnion(u: Union): LogicalPlan = {
+ val uniqueChildren = mutable.ArrayBuffer.empty[LogicalPlan]
+ val uniqueChildrenKey = mutable.HashSet.empty[LogicalPlan]
+
+ u.children.foreach { c =>
+ val key = removeAliasOnlyProject(c).canonicalized
Review comment:
`canonicalized` should cover more cases than `sameOutput`. Note that by
definition two plans with same `canonicalized` plans will always evaluate to
the same result. But their outputs might not be the same.
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]