@@ -21,6 +21,8 @@ import org.apache.spark.sql.catalyst.analysis
2121import org .apache .spark .sql .catalyst .analysis .EliminateSubQueries
2222import org .apache .spark .sql .catalyst .dsl .expressions ._
2323import org .apache .spark .sql .catalyst .dsl .plans ._
24+ import org .apache .spark .sql .catalyst .expressions .Expression
25+ import org .apache .spark .sql .catalyst .planning .ExtractFiltersAndInnerJoins
2426import org .apache .spark .sql .catalyst .plans .PlanTest
2527import org .apache .spark .sql .catalyst .plans .logical .{LocalRelation , LogicalPlan }
2628import org .apache .spark .sql .catalyst .rules .RuleExecutor
@@ -48,7 +50,31 @@ class JoinOrderSuite extends PlanTest {
4850 val testRelation = LocalRelation (' a .int, ' b .int, ' c .int)
4951 val testRelation1 = LocalRelation (' d .int)
5052
51- test(" joins: reorder inner joins" ) {
53+ test(" extract filters and joins" ) {
54+ val x = testRelation.subquery(' x )
55+ val y = testRelation1.subquery(' y )
56+ val z = testRelation.subquery(' z )
57+
58+ def testExtract (plan : LogicalPlan , expected : Option [(Seq [LogicalPlan ], Seq [Expression ])]) {
59+ assert(ExtractFiltersAndInnerJoins .unapply(plan) === expected)
60+ }
61+
62+ testExtract(x, None )
63+ testExtract(x.where(" x.b" .attr === 1 ), None )
64+ testExtract(x.join(y), Some (Seq (x, y), Seq ()))
65+ testExtract(x.join(y, condition = Some (" x.b" .attr === " y.d" .attr)),
66+ Some (Seq (x, y), Seq (" x.b" .attr === " y.d" .attr)))
67+ testExtract(x.join(y).where(" x.b" .attr === " y.d" .attr),
68+ Some (Seq (x, y), Seq (" x.b" .attr === " y.d" .attr)))
69+ testExtract(x.join(y).join(z), Some (Seq (x, y, z), Seq ()))
70+ testExtract(x.join(y).where(" x.b" .attr === " y.d" .attr).join(z),
71+ Some (Seq (x, y, z), Seq (" x.b" .attr === " y.d" .attr)))
72+ testExtract(x.join(y).join(x.join(z)), Some (Seq (x, y, x.join(z)), Seq ()))
73+ testExtract(x.join(y).join(x.join(z)).where(" x.b" .attr === " y.d" .attr),
74+ Some (Seq (x, y, x.join(z)), Seq (" x.b" .attr === " y.d" .attr)))
75+ }
76+
77+ test(" reorder inner joins" ) {
5278 val x = testRelation.subquery(' x )
5379 val y = testRelation1.subquery(' y )
5480 val z = testRelation.subquery(' z )
0 commit comments