Skip to content

Commit

Permalink
Add tests for this error condition
Browse files Browse the repository at this point in the history
  • Loading branch information
andylam-db committed May 22, 2024
1 parent 2e90ea2 commit e8a93a1
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1004,3 +1004,47 @@ Sort [x1#x ASC NULLS FIRST, x2#x ASC NULLS FIRST, y1#x ASC NULLS FIRST, y2#x ASC
+- View (`y`, [y1#x, y2#x])
+- Project [cast(col1#x as int) AS y1#x, cast(col2#x as int) AS y2#x]
+- LocalRelation [col1#x, col2#x]


-- !query
select * from x join y on x1 = y1 and exists (select * from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query analysis
Sort [x1#x ASC NULLS FIRST, x2#x ASC NULLS FIRST, y1#x ASC NULLS FIRST, y2#x ASC NULLS FIRST], true
+- Project [x1#x, x2#x, y1#x, y2#x]
+- Join Inner, ((x1#x = y1#x) AND exists#x [x2#x && y2#x])
: +- Project [z1#x, z2#x]
: +- Filter ((z2#x = outer(x2#x)) AND (z2#x = outer(y2#x)))
: +- SubqueryAlias z
: +- View (`z`, [z1#x, z2#x])
: +- Project [cast(col1#x as int) AS z1#x, cast(col2#x as int) AS z2#x]
: +- LocalRelation [col1#x, col2#x]
:- SubqueryAlias x
: +- View (`x`, [x1#x, x2#x])
: +- Project [cast(col1#x as int) AS x1#x, cast(col2#x as int) AS x2#x]
: +- LocalRelation [col1#x, col2#x]
+- SubqueryAlias y
+- View (`y`, [y1#x, y2#x])
+- Project [cast(col1#x as int) AS y1#x, cast(col2#x as int) AS y2#x]
+- LocalRelation [col1#x, col2#x]


-- !query
select * from x join y on x1 = y1 and not exists (select * from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query analysis
Sort [x1#x ASC NULLS FIRST, x2#x ASC NULLS FIRST, y1#x ASC NULLS FIRST, y2#x ASC NULLS FIRST], true
+- Project [x1#x, x2#x, y1#x, y2#x]
+- Join Inner, ((x1#x = y1#x) AND NOT exists#x [x2#x && y2#x])
: +- Project [z1#x, z2#x]
: +- Filter ((z2#x = outer(x2#x)) AND (z2#x = outer(y2#x)))
: +- SubqueryAlias z
: +- View (`z`, [z1#x, z2#x])
: +- Project [cast(col1#x as int) AS z1#x, cast(col2#x as int) AS z2#x]
: +- LocalRelation [col1#x, col2#x]
:- SubqueryAlias x
: +- View (`x`, [x1#x, x2#x])
: +- Project [cast(col1#x as int) AS x1#x, cast(col2#x as int) AS x2#x]
: +- LocalRelation [col1#x, col2#x]
+- SubqueryAlias y
+- View (`y`, [y1#x, y2#x])
+- Project [cast(col1#x as int) AS y1#x, cast(col2#x as int) AS y2#x]
+- LocalRelation [col1#x, col2#x]
Original file line number Diff line number Diff line change
Expand Up @@ -916,3 +916,47 @@ Sort [x1#x ASC NULLS FIRST, x2#x ASC NULLS FIRST, y1#x ASC NULLS FIRST, y2#x ASC
+- View (`y`, [y1#x, y2#x])
+- Project [cast(col1#x as int) AS y1#x, cast(col2#x as int) AS y2#x]
+- LocalRelation [col1#x, col2#x]


-- !query
select * from x left join y on x1 = y1 and x2 IN (select z1 from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query analysis
Sort [x1#x ASC NULLS FIRST, x2#x ASC NULLS FIRST, y1#x ASC NULLS FIRST, y2#x ASC NULLS FIRST], true
+- Project [x1#x, x2#x, y1#x, y2#x]
+- Join LeftOuter, ((x1#x = y1#x) AND x2#x IN (list#x [x2#x && y2#x]))
: +- Project [z1#x]
: +- Filter ((z2#x = outer(x2#x)) AND (z2#x = outer(y2#x)))
: +- SubqueryAlias z
: +- View (`z`, [z1#x, z2#x])
: +- Project [cast(col1#x as int) AS z1#x, cast(col2#x as int) AS z2#x]
: +- LocalRelation [col1#x, col2#x]
:- SubqueryAlias x
: +- View (`x`, [x1#x, x2#x])
: +- Project [cast(col1#x as int) AS x1#x, cast(col2#x as int) AS x2#x]
: +- LocalRelation [col1#x, col2#x]
+- SubqueryAlias y
+- View (`y`, [y1#x, y2#x])
+- Project [cast(col1#x as int) AS y1#x, cast(col2#x as int) AS y2#x]
+- LocalRelation [col1#x, col2#x]


-- !query
select * from x left join y on x1 = y1 and x2 not IN (select z1 from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query analysis
Sort [x1#x ASC NULLS FIRST, x2#x ASC NULLS FIRST, y1#x ASC NULLS FIRST, y2#x ASC NULLS FIRST], true
+- Project [x1#x, x2#x, y1#x, y2#x]
+- Join LeftOuter, ((x1#x = y1#x) AND NOT x2#x IN (list#x [x2#x && y2#x]))
: +- Project [z1#x]
: +- Filter ((z2#x = outer(x2#x)) AND (z2#x = outer(y2#x)))
: +- SubqueryAlias z
: +- View (`z`, [z1#x, z2#x])
: +- Project [cast(col1#x as int) AS z1#x, cast(col2#x as int) AS z2#x]
: +- LocalRelation [col1#x, col2#x]
:- SubqueryAlias x
: +- View (`x`, [x1#x, x2#x])
: +- Project [cast(col1#x as int) AS x1#x, cast(col2#x as int) AS x2#x]
: +- LocalRelation [col1#x, col2#x]
+- SubqueryAlias y
+- View (`y`, [y1#x, y2#x])
+- Project [cast(col1#x as int) AS y1#x, cast(col2#x as int) AS y2#x]
+- LocalRelation [col1#x, col2#x]
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ select * from x inner join y on x1 = y1 and exists (select * from z where z1 = y
select * from x inner join y on x1 = y1 and not exists (select * from z where z1 = y1) order by x1, x2, y1, y2;
select * from x left join y on x1 = y1 and exists (select * from z where z1 = y1) order by x1, x2, y1, y2;
select * from x left join y on x1 = y1 and not exists (select * from z where z1 = y1) order by x1, x2, y1, y2;

-- Correlated subquery references both left and right children, errors
select * from x join y on x1 = y1 and exists (select * from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2;
select * from x join y on x1 = y1 and not exists (select * from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2;
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ select * from x inner join y on x1 = y1 and y2 IN (select z1 from z where z1 = y
select * from x inner join y on x1 = y1 and y2 not IN (select z1 from z where z1 = y1) order by x1, x2, y1, y2;
select * from x left join y on x1 = y1 and y2 IN (select z1 from z where z1 = y1) order by x1, x2, y1, y2;
select * from x left join y on x1 = y1 and y2 not IN (select z1 from z where z1 = y1) order by x1, x2, y1, y2;

-- Correlated subquery references both left and right children, errors
select * from x left join y on x1 = y1 and x2 IN (select z1 from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2;
select * from x left join y on x1 = y1 and x2 not IN (select z1 from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2;
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,33 @@ struct<x1:int,x2:int,y1:int,y2:int>
1 1 1 4
2 1 NULL NULL
3 4 NULL NULL


-- !query
select * from x join y on x1 = y1 and exists (select * from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_EXPRESSION_IN_JOIN_CONDITION",
"sqlState" : "0A000",
"messageParameters" : {
"subqueryExpression" : "exists(x.x2, y.y2, (z.z2 = x.x2), (z.z2 = y.y2))"
}
}


-- !query
select * from x join y on x1 = y1 and not exists (select * from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_EXPRESSION_IN_JOIN_CONDITION",
"sqlState" : "0A000",
"messageParameters" : {
"subqueryExpression" : "exists(x.x2, y.y2, (z.z2 = x.x2), (z.z2 = y.y2))"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,33 @@ struct<x1:int,x2:int,y1:int,y2:int>
1 1 1 4
2 1 NULL NULL
3 4 NULL NULL


-- !query
select * from x left join y on x1 = y1 and x2 IN (select z1 from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_EXPRESSION_IN_JOIN_CONDITION",
"sqlState" : "0A000",
"messageParameters" : {
"subqueryExpression" : "(x.x2 IN (listquery(x.x2, y.y2, (z.z2 = x.x2), (z.z2 = y.y2))))"
}
}


-- !query
select * from x left join y on x1 = y1 and x2 not IN (select z1 from z where z2 = x2 AND z2 = y2) order by x1, x2, y1, y2
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.AnalysisException
{
"errorClass" : "UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.UNSUPPORTED_CORRELATED_EXPRESSION_IN_JOIN_CONDITION",
"sqlState" : "0A000",
"messageParameters" : {
"subqueryExpression" : "(x.x2 IN (listquery(x.x2, y.y2, (z.z2 = x.x2), (z.z2 = y.y2))))"
}
}

0 comments on commit e8a93a1

Please sign in to comment.