leanken commented on a change in pull request #29614:
URL: https://github.com/apache/spark/pull/29614#discussion_r481755459
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/adaptive/EliminateJoinToEmptyRelation.scala
##########
@@ -36,22 +36,31 @@ import
org.apache.spark.sql.execution.joins.{EmptyHashedRelation, HashedRelation
*/
object EliminateJoinToEmptyRelation extends Rule[LogicalPlan] {
- private def canEliminate(plan: LogicalPlan, relation: HashedRelation):
Boolean = plan match {
- case LogicalQueryStage(_, stage: BroadcastQueryStageExec) if
stage.resultOption.get().isDefined
- && stage.broadcast.relationFuture.get().value == relation => true
- case _ => false
+ private def canEliminate(streamedPlan: LogicalPlan,
+ buildPlan: LogicalPlan, relation: HashedRelation): Boolean = {
+ // If streamedSide of the Join is
ShuffleQueryStageExec(canChangeNumPartitions== false)
+ // it can't be rewritten to EmptyRelation because the conversion will lost
user specified
+ // number partition information.
+ (streamedPlan, buildPlan) match {
+ case (LogicalQueryStage(_, stage: ShuffleQueryStageExec), _)
Review comment:
For example
```
SELECT t.a from (SELECT pm.a as a FROM pm, s where pm.a = s.c) t, ps where
t.a = ps.c
Project [a#3]
+- Join Inner, (a#3 = c#9)
:- Project [a#3]
: +- Join Inner, (a#3 = c#6)
: :- Repartition 77, true
: : +- Project [a#3]
: : +- Filter isnotnull(a#3)
: : +- LocalRelation [a#3, b#4]
: +- Project [c#6]
: +- Filter isnotnull(c#6)
: +- LocalRelation [c#6, d#7]
+- Repartition 99, true
+- Project [c#9]
+- Filter isnotnull(c#9)
+- LocalRelation [c#9, d#10]
```
In this case, the pattern is wrongly missed. because the streamedPlan is not
a LogicalQueryStage but a Project.
I will change the pattern match into Searching the subtree of streamedPlan
to see if a ShuffleQueryStageExec with canChangeNumberPartitions == false
exist, if exists, considered it can't change into empty relation.
----------------------------------------------------------------
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]