Skip to content

Commit d02f6bb

Browse files
committed
fix broadcast selection
1 parent d2a1d12 commit d02f6bb

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
9696
case ExtractEquiJoinKeys(Inner, leftKeys, rightKeys, condition, CanBroadcast(left), right) =>
9797
makeBroadcastHashJoin(leftKeys, rightKeys, left, right, condition, joins.BuildLeft)
9898

99+
case ExtractEquiJoinKeys(
100+
LeftOuter, leftKeys, rightKeys, condition, left, CanBroadcast(right)) =>
101+
joins.BroadcastHashOuterJoin(
102+
leftKeys, rightKeys, LeftOuter, condition, planLater(left), planLater(right)) :: Nil
103+
104+
case ExtractEquiJoinKeys(
105+
RightOuter, leftKeys, rightKeys, condition, CanBroadcast(left), right) =>
106+
joins.BroadcastHashOuterJoin(
107+
leftKeys, rightKeys, RightOuter, condition, planLater(left), planLater(right)) :: Nil
108+
99109
// If the sort merge join option is set, we want to use sort merge join prior to hashjoin.
100110
// And for outer join, we can not put conditions outside of the join
101111
case ExtractEquiJoinKeys(joinType, leftKeys, rightKeys, condition, left, right)
@@ -114,16 +124,6 @@ private[sql] abstract class SparkStrategies extends QueryPlanner[SparkPlan] {
114124
leftKeys, rightKeys, buildSide, planLater(left), planLater(right))
115125
condition.map(Filter(_, hashJoin)).getOrElse(hashJoin) :: Nil
116126

117-
case ExtractEquiJoinKeys(
118-
LeftOuter, leftKeys, rightKeys, condition, left, CanBroadcast(right)) =>
119-
joins.BroadcastHashOuterJoin(
120-
leftKeys, rightKeys, LeftOuter, condition, planLater(left), planLater(right)) :: Nil
121-
122-
case ExtractEquiJoinKeys(
123-
RightOuter, leftKeys, rightKeys, condition, CanBroadcast(left), right) =>
124-
joins.BroadcastHashOuterJoin(
125-
leftKeys, rightKeys, RightOuter, condition, planLater(left), planLater(right)) :: Nil
126-
127127
case ExtractEquiJoinKeys(joinType, leftKeys, rightKeys, condition, left, right) =>
128128
joins.ShuffledHashOuterJoin(
129129
leftKeys, rightKeys, joinType, condition, planLater(left), planLater(right)) :: Nil

sql/core/src/test/scala/org/apache/spark/sql/JoinSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ class JoinSuite extends QueryTest with SQLTestUtils with BeforeAndAfterEach {
152152
Seq(
153153
("SELECT * FROM testData LEFT JOIN testData2 ON key = a", classOf[SortMergeJoin]),
154154
("SELECT * FROM testData RIGHT JOIN testData2 ON key = a where key = 2",
155-
classOf[SortMergeJoin]),
155+
classOf[BroadcastHashOuterJoin]),
156156
("SELECT * FROM testData right join testData2 ON key = a and key = 2",
157-
classOf[SortMergeJoin])
157+
classOf[BroadcastHashOuterJoin])
158158
).foreach { case (query, joinClass) => assertJoin(query, joinClass) }
159159
withSQLConf(SQLConf.SORTMERGE_JOIN.key -> "false") {
160160
Seq(

0 commit comments

Comments
 (0)