@@ -22,6 +22,7 @@ import org.apache.spark.sql.catalyst.analysis._
2222import org .apache .spark .sql .catalyst .expressions ._
2323import org .apache .spark .sql .catalyst .plans .PlanTest
2424import org .apache .spark .sql .catalyst .plans .logical ._
25+ import org .apache .spark .sql .types .BooleanType
2526import org .apache .spark .unsafe .types .CalendarInterval
2627
2728class CatalystQlSuite extends PlanTest {
@@ -203,10 +204,47 @@ class CatalystQlSuite extends PlanTest {
203204 }
204205
205206 test(" subquery" ) {
206- parser.parsePlan(" select (select max(b) from s) ss from t" )
207- parser.parsePlan(" select * from t where a = (select b from s)" )
208- parser.parsePlan(" select * from t where a > (select b from s)" )
209- parser.parsePlan(" select * from t group by g having a = (select b from s)" )
210- parser.parsePlan(" select * from t group by g having a > (select b from s)" )
207+ comparePlans(
208+ parser.parsePlan(" select (select max(b) from s) ss from t" ),
209+ Project (
210+ UnresolvedAlias (
211+ Alias (
212+ ScalarSubquery (
213+ Project (
214+ UnresolvedAlias (
215+ UnresolvedFunction (" max" , UnresolvedAttribute (" b" ) :: Nil , false )) :: Nil ,
216+ UnresolvedRelation (TableIdentifier (" s" )))),
217+ " ss" )(ExprId (0 ))) :: Nil ,
218+ UnresolvedRelation (TableIdentifier (" t" ))))
219+ comparePlans(
220+ parser.parsePlan(" select * from t where a = (select b from s)" ),
221+ Project (
222+ UnresolvedAlias (
223+ UnresolvedStar (None )) :: Nil ,
224+ Filter (
225+ EqualTo (
226+ UnresolvedAttribute (" a" ),
227+ ScalarSubquery (
228+ Project (
229+ UnresolvedAlias (
230+ UnresolvedAttribute (" b" )) :: Nil ,
231+ UnresolvedRelation (TableIdentifier (" s" ))))),
232+ UnresolvedRelation (TableIdentifier (" t" )))))
233+ comparePlans(
234+ parser.parsePlan(" select * from t group by g having a > (select b from s)" ),
235+ Filter (
236+ Cast (
237+ GreaterThan (
238+ UnresolvedAttribute (" a" ),
239+ ScalarSubquery (
240+ Project (
241+ UnresolvedAlias (
242+ UnresolvedAttribute (" b" )) :: Nil ,
243+ UnresolvedRelation (TableIdentifier (" s" ))))),
244+ BooleanType ),
245+ Aggregate (
246+ UnresolvedAttribute (" g" ) :: Nil ,
247+ UnresolvedAlias (UnresolvedStar (None )) :: Nil ,
248+ UnresolvedRelation (TableIdentifier (" t" )))))
211249 }
212250}
0 commit comments