viirya commented on a change in pull request #34557:
URL: https://github.com/apache/spark/pull/34557#discussion_r748005299



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala
##########
@@ -173,16 +173,18 @@ object EliminateOuterJoin extends Rule[LogicalPlan] with 
PredicateHelper {
       if (j.joinType == newJoinType) f else Filter(condition, j.copy(joinType 
= newJoinType))
 
     case a @ Aggregate(_, _, Join(left, _, LeftOuter, _, _))
-        if a.groupOnly && a.references.subsetOf(AttributeSet(left.output)) =>
+        if a.groupOnly && a.references.subsetOf(left.outputSet) =>
       a.copy(child = left)
     case a @ Aggregate(_, _, Join(_, right, RightOuter, _, _))
-        if a.groupOnly && a.references.subsetOf(AttributeSet(right.output)) =>
+        if a.groupOnly && a.references.subsetOf(right.outputSet) =>
       a.copy(child = right)
     case a @ Aggregate(_, _, p @ Project(_, Join(left, _, LeftOuter, _, _)))
-        if a.groupOnly && a.references.subsetOf(AttributeSet(left.output)) =>
+        if a.groupOnly && p.outputSet.subsetOf(a.references) &&
+          
AttributeSet(p.projectList.flatMap(_.references)).subsetOf(left.outputSet) =>
       a.copy(child = p.copy(child = left))
     case a @ Aggregate(_, _, p @ Project(_, Join(_, right, RightOuter, _, _)))
-        if a.groupOnly && a.references.subsetOf(AttributeSet(right.output)) =>
+        if a.groupOnly && p.outputSet.subsetOf(a.references) &&

Review comment:
       Do we need `p.outputSet.subsetOf(a.references)`? Can the `Aggregate` 
refer to any attribute other than `p.outputSet`?




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