@@ -27,9 +27,11 @@ import org.apache.spark.sql.catalyst.rules._
2727class InferFiltersFromConstraintsSuite extends PlanTest {
2828
2929 object Optimize extends RuleExecutor [LogicalPlan ] {
30- val batches = Batch (" InferFilters" , FixedPoint (5 ), InferFiltersFromConstraints ) ::
31- Batch (" PredicatePushdown" , FixedPoint (5 ), PushPredicateThroughJoin ) ::
32- Batch (" CombineFilters" , FixedPoint (5 ), CombineFilters ) :: Nil
30+ val batches = Batch (" InferFilters" , FixedPoint (100 ), InferFiltersFromConstraints ) ::
31+ Batch (" PredicatePushdown" , FixedPoint (100 ),
32+ PushPredicateThroughJoin ,
33+ PushDownPredicate ) ::
34+ Batch (" CombineFilters" , FixedPoint (100 ), CombineFilters ) :: Nil
3335 }
3436
3537 val testRelation = LocalRelation (' a .int, ' b .int, ' c .int)
@@ -120,4 +122,28 @@ class InferFiltersFromConstraintsSuite extends PlanTest {
120122 val optimized = Optimize .execute(originalQuery)
121123 comparePlans(optimized, correctAnswer)
122124 }
125+
126+ test(" don't generate constraints for recursive functions" ) {
127+ val t1 = testRelation.subquery(' t1 )
128+ val t2 = testRelation.subquery(' t2 )
129+ val t3 = testRelation.subquery(' t3 )
130+
131+ val originalQuery = t1.select(' a , ' b .as(' d ), Coalesce (Seq (' a , ' b )).as(' int_col )).as(" t" )
132+ .join(t2, Inner ,
133+ Some (" t.a" .attr === " t2.a" .attr
134+ && " t.d" .attr === " t2.a" .attr
135+ && " t.int_col" .attr === " t2.a" .attr))
136+ .analyze
137+ val correctAnswer = t1.where(IsNotNull (' a ) && ' a === Coalesce (Seq (' a , ' b ))
138+ && IsNotNull (' b ) && ' b === Coalesce (Seq (' a , ' b ))
139+ && IsNotNull (Coalesce (Seq (' a , ' b ))) && ' a === ' b )
140+ .select(' a , ' b .as(' d ), Coalesce (Seq (' a , ' b )).as(' int_col )).as(" t" )
141+ .join(t2.where(IsNotNull (' a )), Inner ,
142+ Some (" t.a" .attr === " t2.a" .attr
143+ && " t.d" .attr === " t2.a" .attr
144+ && " t.int_col" .attr === " t2.a" .attr))
145+ .analyze
146+ val optimized = Optimize .execute(originalQuery)
147+ comparePlans(optimized, correctAnswer)
148+ }
123149}
0 commit comments