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/06/02 03:37:18 UTC

[GitHub] [spark] wangyum commented on a change in pull request #31908: [SPARK-34808][SQL] Removes outer join if it only has DISTINCT on streamed side

wangyum commented on a change in pull request #31908:
URL: https://github.com/apache/spark/pull/31908#discussion_r643628381



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/joins.scala
##########
@@ -165,6 +170,23 @@ object EliminateOuterJoin extends Rule[LogicalPlan] with PredicateHelper {
     case f @ Filter(condition, j @ Join(_, _, RightOuter | LeftOuter | FullOuter, _, _)) =>
       val newJoinType = buildNewJoinType(f, j)
       if (j.joinType == newJoinType) f else Filter(condition, j.copy(joinType = newJoinType))
+
+    case a @ Aggregate(_, _, join @ Join(left, _, LeftOuter, _, _))
+        if a.isDistinct && a.references.subsetOf(AttributeSet(left.output)) &&
+          !canPlanAsBroadcastHashJoin(join, conf) =>

Review comment:
       The result may be incorrect if always remove the join. For example:
   ```
   0: jdbc:hive2://hdc49-mcc10-01-0510-2005-006-> create table test11.t1 using parquet as select id % 3 as a, id as b from range(10);
   +---------+--+
   | Result  |
   +---------+--+
   +---------+--+
   No rows selected (1.611 seconds)
   0: jdbc:hive2://hdc49-mcc10-01-0510-2005-006-> create table test11.t2 using parquet as select id % 3 as x, id as y from range(5);
   +---------+--+
   | Result  |
   +---------+--+
   +---------+--+
   No rows selected (1.043 seconds)
   0: jdbc:hive2://hdc49-mcc10-01-0510-2005-006-> select t1.a from t1 left join t2 on a = x;
   +----+--+
   | a  |
   +----+--+
   | 0  |
   | 0  |
   | 1  |
   | 1  |
   | 0  |
   | 0  |
   | 1  |
   | 1  |
   | 2  |
   | 0  |
   | 0  |
   | 1  |
   | 1  |
   | 2  |
   | 0  |
   | 0  |
   | 2  |
   +----+--+
   17 rows selected (1.409 seconds)
   ```




-- 
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:
users@infra.apache.org



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