Skip to content

Commit 76e7203

Browse files
committed
review
1 parent fa41b44 commit 76e7203

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/subquery.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,6 @@ object ScalarSubquery {
267267
case _ => false
268268
}.isDefined
269269
}
270-
271-
def hasScalarSubquery(e: Expression): Boolean = {
272-
e.find {
273-
case _: ScalarSubquery => true
274-
case _ => false
275-
}.isDefined
276-
}
277270
}
278271

279272
/**

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/PushDownLeftSemiAntiJoin.scala

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,16 @@ object PushDownLeftSemiAntiJoin extends Rule[LogicalPlan] with PredicateHelper {
130130
val newGrandChildren = union.children.map { Join(_, rightOp, joinType, joinCond, hint) }
131131
union.withNewChildren(newGrandChildren)
132132
} else {
133-
val pushDown = splitConjunctivePredicates(joinCond.get)
134-
135-
if (pushDown.nonEmpty) {
136-
val pushDownCond = pushDown.reduceLeft(And)
137-
val output = union.output
138-
val newGrandChildren = union.children.map { grandchild =>
139-
val newCond = pushDownCond transform {
140-
case e if output.exists(_.semanticEquals(e)) =>
141-
grandchild.output(output.indexWhere(_.semanticEquals(e)))
142-
}
143-
assert(newCond.references.subsetOf(grandchild.outputSet ++ rightOp.outputSet))
144-
Join(grandchild, rightOp, joinType, Option(newCond), hint)
133+
val output = union.output
134+
val newGrandChildren = union.children.map { grandchild =>
135+
val newCond = joinCond.get transform {
136+
case e if output.exists(_.semanticEquals(e)) =>
137+
grandchild.output(output.indexWhere(_.semanticEquals(e)))
145138
}
146-
union.withNewChildren(newGrandChildren)
147-
} else {
148-
// Nothing to push down
149-
join
139+
assert(newCond.references.subsetOf(grandchild.outputSet ++ rightOp.outputSet))
140+
Join(grandchild, rightOp, joinType, Option(newCond), hint)
150141
}
142+
union.withNewChildren(newGrandChildren)
151143
}
152144

153145
// LeftSemi/LeftAnti over UnaryNode
@@ -182,22 +174,22 @@ object PushDownLeftSemiAntiJoin extends Rule[LogicalPlan] with PredicateHelper {
182174
private def pushDownJoin(
183175
join: Join,
184176
grandchild: LogicalPlan)(insertFilter: Expression => LogicalPlan): LogicalPlan = {
185-
val (pushDown, stayUp) = if (join.condition.isDefined) {
186-
splitConjunctivePredicates(join.condition.get)
187-
.partition {_.references.subsetOf(grandchild.outputSet ++ join.right.outputSet)}
177+
if (join.condition.isEmpty) {
178+
insertFilter(null)
188179
} else {
189-
(Nil, Nil)
190-
}
180+
val (pushDown, stayUp) = splitConjunctivePredicates(join.condition.get)
181+
.partition {_.references.subsetOf(grandchild.outputSet ++ join.right.outputSet)}
191182

192-
if (pushDown.nonEmpty) {
193-
val newChild = insertFilter(pushDown.reduceLeft(And))
194-
if (stayUp.nonEmpty) {
195-
Filter(stayUp.reduceLeft(And), newChild)
183+
if (pushDown.nonEmpty) {
184+
val newChild = insertFilter(pushDown.reduceLeft(And))
185+
if (stayUp.nonEmpty) {
186+
Filter(stayUp.reduceLeft(And), newChild)
187+
} else {
188+
newChild
189+
}
196190
} else {
197-
newChild
191+
join
198192
}
199-
} else {
200-
join
201193
}
202194
}
203195
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/LeftSemiAntiJoinPushDownSuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,19 @@ class LeftSemiPushdownSuite extends PlanTest {
257257
.analyze
258258
comparePlans(optimized, correctAnswer)
259259
}
260+
261+
test("Unary: LeftSemiAnti join pushdown - empty join condition") {
262+
val originalQuery = testRelation
263+
.select(star())
264+
.repartition(1)
265+
.join(testRelation1, joinType = LeftSemi, condition = None)
266+
267+
val optimized = Optimize.execute(originalQuery.analyze)
268+
val correctAnswer = testRelation
269+
.join(testRelation1, joinType = LeftSemi, condition = None)
270+
.select('a, 'b, 'c)
271+
.repartition(1)
272+
.analyze
273+
comparePlans(optimized, correctAnswer)
274+
}
260275
}

0 commit comments

Comments
 (0)