You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/11/12 06:27:33 UTC

[GitHub] [spark] viirya commented on a change in pull request #34557: [SPARK-37292][SQL] Removes outer join if it only has DISTINCT on streamed side with alias

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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org