cloud-fan commented on a change in pull request #35214:
URL: https://github.com/apache/spark/pull/35214#discussion_r785702146



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -766,18 +767,24 @@ object PushProjectionThroughUnion extends 
Rule[LogicalPlan] with PredicateHelper
     _.containsAllPatterns(UNION, PROJECT)) {
 
     // Push down deterministic projection through UNION ALL
-    case p @ Project(projectList, u: Union) =>
+    case Project(projectList, u: Union) if projectList.forall(_.deterministic) 
=>
       assert(u.children.nonEmpty)
-      if (projectList.forall(_.deterministic)) {
-        val newFirstChild = Project(projectList, u.children.head)
-        val newOtherChildren = u.children.tail.map { child =>
-          val rewrites = buildRewrites(u.children.head, child)
-          Project(projectList.map(pushToRight(_, rewrites)), child)
-        }
-        u.copy(children = newFirstChild +: newOtherChildren)
-      } else {
-        p
+      val newFirstChild = Project(projectList, u.children.head)
+      val newOtherChildren = u.children.tail.map { child =>
+        val rewrites = buildRewrites(u.children.head, child)
+        Project(projectList.map(pushToRight(_, rewrites)), child)
+      }
+      u.copy(children = newFirstChild +: newOtherChildren)
+
+    // Push down deterministic projection through SQL UNION
+    case Project(projectList, Distinct(u: Union)) if 
projectList.forall(_.deterministic) =>

Review comment:
       hmm, how does this help eliminate aggregates?




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

Reply via email to