Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6f575a0
first attempt.
gatorsmile Aug 12, 2016
9888f8a
add files
gatorsmile Aug 12, 2016
239191c
batch 1
gatorsmile Aug 13, 2016
aaeb298
batch 1
gatorsmile Aug 13, 2016
5f22316
revert
gatorsmile Aug 13, 2016
3fe55f1
batch 2
gatorsmile Aug 13, 2016
98f7f11
added meaningful comments
gatorsmile Aug 14, 2016
a26bdeb
added meaningful comments
gatorsmile Aug 14, 2016
cdea1a3
added meaningful comments
gatorsmile Aug 14, 2016
9c67e69
batch 3
gatorsmile Aug 14, 2016
5bd85c2
two more cases
gatorsmile Aug 14, 2016
7bf9739
code clean
gatorsmile Aug 17, 2016
701bd74
address comments
gatorsmile Aug 17, 2016
376e99a
add using joins.
gatorsmile Aug 17, 2016
7c6f85a
using cast for null.
gatorsmile Aug 17, 2016
4bd38d2
move outer joins to outer-join.sql and move left-semi join to left-se…
gatorsmile Aug 17, 2016
a059c77
more test cases
gatorsmile Aug 17, 2016
cf9a233
code clean
gatorsmile Aug 18, 2016
b4801e0
code clean
gatorsmile Aug 18, 2016
5ecfc4f
Merge remote-tracking branch 'upstream/master' into auto_join
gatorsmile Aug 20, 2016
bf55624
update based on the lastest fix.
gatorsmile Aug 20, 2016
42b3c69
remove the comments (xyz.q)
gatorsmile Aug 22, 2016
1118626
change the table name for testData and testData2
gatorsmile Aug 22, 2016
c73134e
rename src by duplicateRowData
gatorsmile Aug 22, 2016
a204f52
rename src1 by nullData
gatorsmile Aug 22, 2016
046c3c3
rename srcpart by partitionedData
gatorsmile Aug 22, 2016
9c6be8e
Merge remote-tracking branch 'upstream/master' into auto_join
gatorsmile Aug 22, 2016
1969ca2
fix.
gatorsmile Aug 22, 2016
e2677da
revert
gatorsmile Aug 22, 2016
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
14 changes: 7 additions & 7 deletions sql/core/src/test/resources/sql-tests/inputs/arithmetic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ select -100;
select +230;
select -5.2;
select +6.8e0;
select -key, +key from testdata where key = 2;
select -(key + 1), - key + 1, +(key + 5) from testdata where key = 1;
select -max(key), +max(key) from testdata;
select -key, +key from uniqueRowData where key = 2;
select -(key + 1), - key + 1, +(key + 5) from uniqueRowData where key = 1;
select -max(key), +max(key) from uniqueRowData;
select - (-10);
select + (-key) from testdata where key = 32;
select - (+max(key)) from testdata;
select + (-key) from uniqueRowData where key = 32;
select - (+max(key)) from uniqueRowData;
select - - 3;
select - + 20;
select + + 100;
select - - max(key) from testdata;
select + - key from testdata where key = 33;
select - - max(key) from uniqueRowData;
select + - key from uniqueRowData where key = 33;

-- div
select 5 / 2;
Expand Down
229 changes: 229 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
-- join nested table expressions
SELECT a.k1, a.v1, a.k2, a.v2
FROM (
SELECT src1.key as k1, src1.value as v1,
src2.key as k2, src2.value as v2 FROM
(SELECT * FROM duplicateRowData WHERE duplicateRowData.key < 200) src1
JOIN
(SELECT * FROM duplicateRowData WHERE duplicateRowData.key < 200) src2
SORT BY k1, v1, k2, v2
) a;

-- self-join + join condition
SELECT src1.key, src2.value
FROM duplicateRowData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key);

-- equi inner join + inner join with a complex join condition
SELECT src1.key, src3.value
FROM duplicateRowData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key)
JOIN duplicateRowData src3 ON (src1.key + src2.key = src3.key);

-- equi inner join + equi inner join
SELECT src1.key, src3.value
FROM duplicateRowData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key)
JOIN duplicateRowData src3 ON (src1.key = src3.key);

-- inner join + join condition + filter
SELECT src1.key, src2.value
FROM partitionedData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key)
WHERE src1.ds = '2008-04-08' and src1.hr = '12';

-- equi inner join + table.star expansion in nested table expression
FROM
(SELECT duplicateRowData.* from duplicateRowData) x
JOIN
(SELECT duplicateRowData.* from duplicateRowData) Y
ON (x.key = Y.key)
select Y.key, Y.value;

-- inner join with a complex join condition over nested table expressions
SELECT src1.c1, src2.c4
FROM
(SELECT duplicateRowData.key as c1, duplicateRowData.value as c2 from duplicateRowData) src1
JOIN
(SELECT duplicateRowData.key as c3, duplicateRowData.value as c4 from duplicateRowData) src2
ON src1.c1 = src2.c3 AND src1.c1 < 200;

-- two inner join with a complex join condition over nested table expressions
SELECT src1.c1, src2.c4
FROM
(SELECT duplicateRowData.key as c1, duplicateRowData.value as c2 from duplicateRowData) src1
JOIN
(SELECT duplicateRowData.key as c3, duplicateRowData.value as c4 from duplicateRowData) src2
ON src1.c1 = src2.c3 AND src1.c1 < 200
JOIN
(SELECT duplicateRowData.key as c5, duplicateRowData.value as c6 from duplicateRowData) src3
ON src1.c1 = src3.c5 AND src3.c5 < 100;

-- two inner join with a complex join condition over nested table expressions
SELECT src1.c1, src2.c4
FROM
(SELECT duplicateRowData.key as c1, duplicateRowData.value as c2 from duplicateRowData) src1
JOIN
(SELECT duplicateRowData.key as c3, duplicateRowData.value as c4 from duplicateRowData) src2
ON src1.c1 = src2.c3 AND src1.c1 < 250
JOIN
(SELECT duplicateRowData.key as c5, duplicateRowData.value as c6 from duplicateRowData) src3
ON src1.c1 + src2.c3 = src3.c5 AND src3.c5 < 400;

-- join two different tables
FROM duplicateRowData JOIN partitionedData
ON duplicateRowData.key = partitionedData.key AND partitionedData.ds = '2008-04-08'
AND duplicateRowData.key > 200
SELECT duplicateRowData.key, partitionedData.value;

-- join + sort by
SELECT a.k1, a.v1, a.k2, a.v2
FROM (
SELECT src1.key as k1, src1.value as v1, src2.key as k2, src2.value as v2
FROM duplicateRowData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key)
SORT BY k1, v1, k2, v2
) a;

-- inner join with a filter above join and a filter below join
SELECT subq.key, tab.value
FROM
(select a.key, a.value from duplicateRowData a where a.key > 100 ) subq
JOIN duplicateRowData tab
ON (subq.key = tab.key and subq.key > 150 and subq.value = tab.value)
where tab.key < 200;

-- star expansion in nested table expression
SELECT src1.*, src2.*
FROM duplicateRowData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key);

-- join + disjunctive conditions
SELECT src1.key, src2.value
FROM partitionedData src1 JOIN duplicateRowData src2 ON (src1.key = src2.key)
where (src1.ds = '2008-04-08' or src1.ds = '2008-04-09' )and (src1.hr = '12' or src1.hr = '11');

-- nested join
SELECT src5.src1_value
FROM
(SELECT src3.*, src4.value as src4_value, src4.key as src4_key
FROM duplicateRowData src4
JOIN (SELECT src2.*, src1.key as src1_key, src1.value as src1_value
FROM duplicateRowData src1
JOIN duplicateRowData src2 ON src1.key = src2.key) src3
ON src3.src1_key = src4.key) src5;

-- Cartesian join
SELECT * FROM duplicateRowData src1 JOIN duplicateRowData src2
WHERE src1.key < 200 and src2.key < 200
SORT BY src1.key, src1.value, src2.key, src2.value;

-- join
WITH tst1 AS (SELECT a.key, count(1) as cnt FROM duplicateRowData a group by a.key)
SELECT sum(a.cnt) FROM tst1 a JOIN tst1 b ON a.key = b.key;

-- aggregate over join results
SELECT x.key, count(1)
FROM nullData x JOIN duplicateRowData y
ON (x.key = y.key) group by x.key order by x.key;

-- join over set operation over aggregate
SELECT count(1)
FROM
(
SELECT duplicateRowData.key, duplicateRowData.value from duplicateRowData
UNION ALL
SELECT DISTINCT duplicateRowData.key, duplicateRowData.value from duplicateRowData
) src_12
JOIN
(
SELECT duplicateRowData.key as k, duplicateRowData.value as v from duplicateRowData
) src3
ON src_12.key = src3.k AND src3.k < 300;

-- inner join with sorted by nested table expression
FROM
(SELECT duplicateRowData.* FROM duplicateRowData sort by key) x
JOIN
(SELECT duplicateRowData.* FROM duplicateRowData sort by value) Y
ON (x.key = Y.key)
select Y.key,Y.value;

-- inner + inner with sorted by nested table expression
FROM
(SELECT duplicateRowData.* FROM duplicateRowData sort by key) x
JOIN
(SELECT duplicateRowData.* FROM duplicateRowData sort by value) Y
ON (x.key = Y.key)
JOIN
(SELECT duplicateRowData.* FROM duplicateRowData sort by value) Z
ON (x.key = Z.key)
select Y.key,Y.value;

-- join over set operation
SELECT x.key, x.value, subq1.value
FROM
( SELECT x.key as key, x.value as value from duplicateRowData x where x.key < 200
UNION ALL
SELECT x1.key as key, x1.value as value from duplicateRowData x1 where x1.key > 100
) subq1
JOIN nullData x ON (x.key = subq1.key);

-- join over set operation over aggregate
SELECT x.key, x.value, subq1.cnt
FROM
( SELECT x.key as key, count(1) as cnt from duplicateRowData x where x.key < 200 group by x.key
UNION ALL
SELECT x1.key as key, count(1) as cnt from duplicateRowData x1 where x1.key > 100 group by x1.key
) subq1
JOIN nullData x ON (x.key = subq1.key);

-- self join with aliases
SELECT x.key, COUNT(*)
FROM duplicateRowData x JOIN duplicateRowData y ON x.key = y.key
GROUP BY x.key;

-- inner join with one-match-per-row filtering predicates (where)
SELECT * FROM uppercasedata u JOIN lowercasedata l WHERE u.n = l.N;

-- inner join with one-match-per-row join conditions (on)
SELECT * FROM uppercasedata u JOIN lowercasedata l ON u.n = l.N;

-- inner join with multiple-match-per-row filtering predicates (where)
SELECT * FROM
(SELECT * FROM duplicateColumnValueData WHERE a = 1) x JOIN
(SELECT * FROM duplicateColumnValueData WHERE a = 1) y
WHERE x.a = y.a;

-- inner join with no-match-per-row filtering predicates (where)
SELECT * FROM
(SELECT * FROM duplicateColumnValueData WHERE a = 1) x JOIN
(SELECT * FROM duplicateColumnValueData WHERE a = 2) y
WHERE x.a = y.a;

-- inner join ON with table name as qualifier
SELECT * FROM upperCaseData JOIN lowerCaseData ON lowerCaseData.n = upperCaseData.N;

-- qualified select with inner join ON with table name as qualifier
SELECT upperCaseData.N, upperCaseData.L FROM upperCaseData JOIN lowerCaseData
ON lowerCaseData.n = upperCaseData.N;

-- SPARK-4120 Join of multiple tables does not work in SparkSQL
SELECT a.key, b.key, c.key
FROM uniqueRowData a,uniqueRowData b,uniqueRowData c
where a.key = b.key and a.key = c.key and a.key < 5;

-- big inner join, 4 matches per row
SELECT x.key, x.value, y.key, y.value, count(1) FROM
(SELECT * FROM uniqueRowData UNION ALL
SELECT * FROM uniqueRowData UNION ALL
SELECT * FROM uniqueRowData UNION ALL
SELECT * FROM uniqueRowData) x JOIN
(SELECT * FROM uniqueRowData UNION ALL
SELECT * FROM uniqueRowData UNION ALL
SELECT * FROM uniqueRowData UNION ALL
SELECT * FROM uniqueRowData) y
WHERE x.key = y.key group by x.key, x.value, y.key, y.value;

-- mixed-case keywords
SeleCT * from
(select * from upperCaseData WherE N <= 4) leftTable fuLL OUtER joiN
(sElEcT * FROM upperCaseData whERe N >= 3) rightTable
oN leftTable.N = rightTable.N;

-- Supporting relational operator '<=>' in Spark SQL
SELECT * FROM nullData as a JOIN nullData as b on a.value <=> b.value;
14 changes: 14 additions & 0 deletions sql/core/src/test/resources/sql-tests/inputs/left-semi-join.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- left semi greater than predicate
SELECT *
FROM duplicateColumnValueData x LEFT SEMI JOIN duplicateColumnValueData y
ON x.a >= y.a + 2;

-- left semi greater than predicate and equal operator #1
SELECT *
FROM duplicateColumnValueData x LEFT SEMI JOIN duplicateColumnValueData y
ON x.b = y.b and x.a >= y.a + 2;

-- left semi greater than predicate and equal operator #2
SELECT *
FROM duplicateColumnValueData x LEFT SEMI JOIN duplicateColumnValueData y
ON x.b = y.a and x.a >= y.b + 1;
14 changes: 7 additions & 7 deletions sql/core/src/test/resources/sql-tests/inputs/limit.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@

-- limit on various data types
select * from testdata limit 2;
select * from uniqueRowData limit 2;
select * from arraydata limit 2;
select * from mapdata limit 2;

-- foldable non-literal in limit
select * from testdata limit 2 + 1;
select * from uniqueRowData limit 2 + 1;

select * from testdata limit CAST(1 AS int);
select * from uniqueRowData limit CAST(1 AS int);

-- limit must be non-negative
select * from testdata limit -1;
select * from uniqueRowData limit -1;

-- limit must be foldable
select * from testdata limit key > 3;
select * from uniqueRowData limit key > 3;

-- limit must be integer
select * from testdata limit true;
select * from testdata limit 'a';
select * from uniqueRowData limit true;
select * from uniqueRowData limit 'a';

-- limit within a subquery
select * from (select * from range(10) limit 5) where id > 3;
Loading