@@ -37,17 +37,18 @@ class RewriteSubquerySuite extends PlanTest {
3737 InferFiltersFromConstraints ,
3838 PushDownPredicate ,
3939 CollapseProject ,
40+ CombineFilters ,
4041 RemoveRedundantProject ) :: Nil
4142 }
4243
44+ val relation = LocalRelation (' a .int, ' b .int)
45+ val relInSubquery = LocalRelation (' x .int, ' y .int, ' z .int)
46+
4347 test(" Column pruning after rewriting predicate subquery" ) {
4448 withSQLConf(SQLConf .CONSTRAINT_PROPAGATION_ENABLED .key -> " false" ) {
45- val relation = LocalRelation (' a .int, ' b .int)
46- val relInSubquery = LocalRelation (' x .int, ' y .int, ' z .int)
47-
4849 val query = relation.where(' a .in(ListQuery (relInSubquery.select(' x )))).select(' a )
49-
5050 val optimized = Optimize .execute(query.analyze)
51+
5152 val correctAnswer = relation
5253 .select(' a )
5354 .join(relInSubquery.select(' x ), LeftSemi , Some (' a === ' x ))
@@ -59,12 +60,9 @@ class RewriteSubquerySuite extends PlanTest {
5960
6061 test(" Infer filters and push down predicate after rewriting predicate subquery" ) {
6162 withSQLConf(SQLConf .CONSTRAINT_PROPAGATION_ENABLED .key -> " true" ) {
62- val relation = LocalRelation (' a .int, ' b .int)
63- val relInSubquery = LocalRelation (' x .int, ' y .int, ' z .int)
64-
6563 val query = relation.where(' a .in(ListQuery (relInSubquery.select(' x )))).select(' a )
66-
6764 val optimized = Optimize .execute(query.analyze)
65+
6866 val correctAnswer = relation
6967 .where(IsNotNull (' a )).select(' a )
7068 .join(relInSubquery.where(IsNotNull (' x )).select(' x ), LeftSemi , Some (' a === ' x ))
@@ -74,4 +72,17 @@ class RewriteSubquerySuite extends PlanTest {
7472 }
7573 }
7674
75+ test(" combine filters after rewriting predicate subquery" ) {
76+ val query = relation.where(' a .in(ListQuery (relInSubquery.select(' x ).where(' y > 1 )))).select(' a )
77+ val optimized = Optimize .execute(query.analyze)
78+
79+ val correctAnswer = relation
80+ .where(IsNotNull (' a )).select(' a )
81+ .join(relInSubquery.where(IsNotNull (' x ) && IsNotNull (' y ) && ' y > 1 ).select(' x ),
82+ LeftSemi , Some (' a === ' x ))
83+ .analyze
84+
85+ comparePlans(optimized, correctAnswer)
86+ }
87+
7788}
0 commit comments