Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Cross join detection and error checking is done in JoinSuite since explain output is
-- used in the error message and the ids are not stable. Only positive cases are checked here.
-- This test file was converted from cross-join.sql.

create temporary view nt1 as select * from values
("one", 1),
("two", 2),
("three", 3)
as nt1(k, v1);

create temporary view nt2 as select * from values
("one", 1),
("two", 22),
("one", 5)
as nt2(k, v2);

-- Cross joins with and without predicates
SELECT * FROM nt1 cross join nt2;
SELECT * FROM nt1 cross join nt2 where udf(nt1.k) = udf(nt2.k);
SELECT * FROM nt1 cross join nt2 on (udf(nt1.k) = udf(nt2.k));
SELECT * FROM nt1 cross join nt2 where udf(nt1.v1) = "1" and udf(nt2.v2) = "22";

SELECT udf(a.key), udf(b.key) FROM
(SELECT udf(k) key FROM nt1 WHERE v1 < 2) a
CROSS JOIN
(SELECT udf(k) key FROM nt2 WHERE v2 = 22) b;

-- Join reordering
create temporary view A(a, va) as select * from nt1;
create temporary view B(b, vb) as select * from nt1;
create temporary view C(c, vc) as select * from nt1;
create temporary view D(d, vd) as select * from nt1;

-- Allowed since cross join with C is explicit
select * from ((A join B on (udf(a) = udf(b))) cross join C) join D on (udf(a) = udf(d));
-- Cross joins with non-equal predicates
SELECT * FROM nt1 CROSS JOIN nt2 ON (udf(nt1.k) > udf(nt2.k));
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 13


-- !query 0
create temporary view nt1 as select * from values
("one", 1),
("two", 2),
("three", 3)
as nt1(k, v1)
-- !query 0 schema
struct<>
-- !query 0 output



-- !query 1
create temporary view nt2 as select * from values
("one", 1),
("two", 22),
("one", 5)
as nt2(k, v2)
-- !query 1 schema
struct<>
-- !query 1 output



-- !query 2
SELECT * FROM nt1 cross join nt2
-- !query 2 schema
struct<k:string,v1:int,k:string,v2:int>
-- !query 2 output
one 1 one 1
one 1 one 5
one 1 two 22
three 3 one 1
three 3 one 5
three 3 two 22
two 2 one 1
two 2 one 5
two 2 two 22


-- !query 3
SELECT * FROM nt1 cross join nt2 where udf(nt1.k) = udf(nt2.k)
-- !query 3 schema
struct<k:string,v1:int,k:string,v2:int>
-- !query 3 output
one 1 one 1
one 1 one 5
two 2 two 22


-- !query 4
SELECT * FROM nt1 cross join nt2 on (udf(nt1.k) = udf(nt2.k))
-- !query 4 schema
struct<k:string,v1:int,k:string,v2:int>
-- !query 4 output
one 1 one 1
one 1 one 5
two 2 two 22


-- !query 5
SELECT * FROM nt1 cross join nt2 where udf(nt1.v1) = "1" and udf(nt2.v2) = "22"
-- !query 5 schema
struct<k:string,v1:int,k:string,v2:int>
-- !query 5 output
one 1 two 22


-- !query 6
SELECT udf(a.key), udf(b.key) FROM
(SELECT udf(k) key FROM nt1 WHERE v1 < 2) a
CROSS JOIN
(SELECT udf(k) key FROM nt2 WHERE v2 = 22) b
-- !query 6 schema
struct<CAST(udf(cast(key as string)) AS STRING):string,CAST(udf(cast(key as string)) AS STRING):string>
-- !query 6 output
one two


-- !query 7
create temporary view A(a, va) as select * from nt1
-- !query 7 schema
struct<>
-- !query 7 output



-- !query 8
create temporary view B(b, vb) as select * from nt1
-- !query 8 schema
struct<>
-- !query 8 output



-- !query 9
create temporary view C(c, vc) as select * from nt1
-- !query 9 schema
struct<>
-- !query 9 output



-- !query 10
create temporary view D(d, vd) as select * from nt1
-- !query 10 schema
struct<>
-- !query 10 output



-- !query 11
select * from ((A join B on (udf(a) = udf(b))) cross join C) join D on (udf(a) = udf(d))
-- !query 11 schema
struct<a:string,va:int,b:string,vb:int,c:string,vc:int,d:string,vd:int>
-- !query 11 output
one 1 one 1 one 1 one 1
one 1 one 1 three 3 one 1
one 1 one 1 two 2 one 1
three 3 three 3 one 1 three 3
three 3 three 3 three 3 three 3
three 3 three 3 two 2 three 3
two 2 two 2 one 1 two 2
two 2 two 2 three 3 two 2
two 2 two 2 two 2 two 2


-- !query 12
SELECT * FROM nt1 CROSS JOIN nt2 ON (udf(nt1.k) > udf(nt2.k))
-- !query 12 schema
struct<k:string,v1:int,k:string,v2:int>
-- !query 12 output
three 3 one 1
three 3 one 5
two 2 one 1
two 2 one 5