Skip to content

Commit 2cf0491

Browse files
wangyumdongjoon-hyun
authored andcommitted
[SPARK-28388][SQL][TEST] Port select_implicit.sql
## What changes were proposed in this pull request? This PR is to port numeric.sql from PostgreSQL regression tests. https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/select_implicit.sql The expected results can be found in the link: https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/expected/select_implicit.out When porting the test cases, found one PostgreSQL specific features that do not exist in Spark SQL: [SPARK-28329](https://issues.apache.org/jira/browse/SPARK-28329): SELECT INTO syntax ## How was this patch tested? N/A Closes apache#25152 from wangyum/SPARK-28388. Authored-by: Yuming Wang <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent 8acc22c commit 2cf0491

File tree

2 files changed

+576
-0
lines changed

2 files changed

+576
-0
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
--
2+
-- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
3+
--
4+
--
5+
-- SELECT_IMPLICIT
6+
-- Test cases for queries with ordering terms missing from the target list.
7+
-- This used to be called "junkfilter.sql".
8+
-- The parser uses the term "resjunk" to handle these cases.
9+
-- - thomas 1998-07-09
10+
-- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/select_implicit.sql
11+
--
12+
13+
-- load test data
14+
CREATE TABLE test_missing_target (a int, b int, c string, d string) using parquet;
15+
INSERT INTO test_missing_target VALUES (0, 1, 'XXXX', 'A');
16+
INSERT INTO test_missing_target VALUES (1, 2, 'ABAB', 'b');
17+
INSERT INTO test_missing_target VALUES (2, 2, 'ABAB', 'c');
18+
INSERT INTO test_missing_target VALUES (3, 3, 'BBBB', 'D');
19+
INSERT INTO test_missing_target VALUES (4, 3, 'BBBB', 'e');
20+
INSERT INTO test_missing_target VALUES (5, 3, 'bbbb', 'F');
21+
INSERT INTO test_missing_target VALUES (6, 4, 'cccc', 'g');
22+
INSERT INTO test_missing_target VALUES (7, 4, 'cccc', 'h');
23+
INSERT INTO test_missing_target VALUES (8, 4, 'CCCC', 'I');
24+
INSERT INTO test_missing_target VALUES (9, 4, 'CCCC', 'j');
25+
26+
27+
-- w/ existing GROUP BY target
28+
SELECT c, count(*) FROM test_missing_target GROUP BY test_missing_target.c ORDER BY c;
29+
30+
-- w/o existing GROUP BY target using a relation name in GROUP BY clause
31+
SELECT count(*) FROM test_missing_target GROUP BY test_missing_target.c ORDER BY c;
32+
33+
-- w/o existing GROUP BY target and w/o existing a different ORDER BY target
34+
-- failure expected
35+
SELECT count(*) FROM test_missing_target GROUP BY a ORDER BY b;
36+
37+
-- w/o existing GROUP BY target and w/o existing same ORDER BY target
38+
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b;
39+
40+
-- w/ existing GROUP BY target using a relation name in target
41+
SELECT test_missing_target.b, count(*)
42+
FROM test_missing_target GROUP BY b ORDER BY b;
43+
44+
-- w/o existing GROUP BY target
45+
SELECT c FROM test_missing_target ORDER BY a;
46+
47+
-- w/o existing ORDER BY target
48+
SELECT count(*) FROM test_missing_target GROUP BY b ORDER BY b desc;
49+
50+
-- group using reference number
51+
SELECT count(*) FROM test_missing_target ORDER BY 1 desc;
52+
53+
-- order using reference number
54+
SELECT c, count(*) FROM test_missing_target GROUP BY 1 ORDER BY 1;
55+
56+
-- group using reference number out of range
57+
-- failure expected
58+
SELECT c, count(*) FROM test_missing_target GROUP BY 3;
59+
60+
-- group w/o existing GROUP BY and ORDER BY target under ambiguous condition
61+
-- failure expected
62+
SELECT count(*) FROM test_missing_target x, test_missing_target y
63+
WHERE x.a = y.a
64+
GROUP BY b ORDER BY b;
65+
66+
-- order w/ target under ambiguous condition
67+
-- failure NOT expected
68+
SELECT a, a FROM test_missing_target
69+
ORDER BY a;
70+
71+
-- order expression w/ target under ambiguous condition
72+
-- failure NOT expected
73+
SELECT a/2, a/2 FROM test_missing_target
74+
ORDER BY a/2;
75+
76+
-- group expression w/ target under ambiguous condition
77+
-- failure NOT expected
78+
SELECT a/2, a/2 FROM test_missing_target
79+
GROUP BY a/2 ORDER BY a/2;
80+
81+
-- group w/ existing GROUP BY target under ambiguous condition
82+
SELECT x.b, count(*) FROM test_missing_target x, test_missing_target y
83+
WHERE x.a = y.a
84+
GROUP BY x.b ORDER BY x.b;
85+
86+
-- group w/o existing GROUP BY target under ambiguous condition
87+
SELECT count(*) FROM test_missing_target x, test_missing_target y
88+
WHERE x.a = y.a
89+
GROUP BY x.b ORDER BY x.b;
90+
91+
-- [SPARK-28329] SELECT INTO syntax
92+
-- group w/o existing GROUP BY target under ambiguous condition
93+
-- into a table
94+
-- SELECT count(*) INTO TABLE test_missing_target2
95+
-- FROM test_missing_target x, test_missing_target y
96+
-- WHERE x.a = y.a
97+
-- GROUP BY x.b ORDER BY x.b;
98+
-- SELECT * FROM test_missing_target2;
99+
100+
101+
-- Functions and expressions
102+
103+
-- w/ existing GROUP BY target
104+
SELECT a%2, count(b) FROM test_missing_target
105+
GROUP BY test_missing_target.a%2
106+
ORDER BY test_missing_target.a%2;
107+
108+
-- w/o existing GROUP BY target using a relation name in GROUP BY clause
109+
SELECT count(c) FROM test_missing_target
110+
GROUP BY lower(test_missing_target.c)
111+
ORDER BY lower(test_missing_target.c);
112+
113+
-- w/o existing GROUP BY target and w/o existing a different ORDER BY target
114+
-- failure expected
115+
SELECT count(a) FROM test_missing_target GROUP BY a ORDER BY b;
116+
117+
-- w/o existing GROUP BY target and w/o existing same ORDER BY target
118+
SELECT count(b) FROM test_missing_target GROUP BY b/2 ORDER BY b/2;
119+
120+
-- w/ existing GROUP BY target using a relation name in target
121+
SELECT lower(test_missing_target.c), count(c)
122+
FROM test_missing_target GROUP BY lower(c) ORDER BY lower(c);
123+
124+
-- w/o existing GROUP BY target
125+
SELECT a FROM test_missing_target ORDER BY upper(d);
126+
127+
-- w/o existing ORDER BY target
128+
SELECT count(b) FROM test_missing_target
129+
GROUP BY (b + 1) / 2 ORDER BY (b + 1) / 2 desc;
130+
131+
-- group w/o existing GROUP BY and ORDER BY target under ambiguous condition
132+
-- failure expected
133+
SELECT count(x.a) FROM test_missing_target x, test_missing_target y
134+
WHERE x.a = y.a
135+
GROUP BY b/2 ORDER BY b/2;
136+
137+
-- group w/ existing GROUP BY target under ambiguous condition
138+
SELECT x.b/2, count(x.b) FROM test_missing_target x, test_missing_target y
139+
WHERE x.a = y.a
140+
GROUP BY x.b/2 ORDER BY x.b/2;
141+
142+
-- group w/o existing GROUP BY target under ambiguous condition
143+
-- failure expected due to ambiguous b in count(b)
144+
SELECT count(b) FROM test_missing_target x, test_missing_target y
145+
WHERE x.a = y.a
146+
GROUP BY x.b/2;
147+
148+
-- [SPARK-28329] SELECT INTO syntax
149+
-- group w/o existing GROUP BY target under ambiguous condition
150+
-- into a table
151+
-- SELECT count(x.b) INTO TABLE test_missing_target3
152+
-- FROM test_missing_target x, test_missing_target y
153+
-- WHERE x.a = y.a
154+
-- GROUP BY x.b/2 ORDER BY x.b/2;
155+
-- SELECT * FROM test_missing_target3;
156+
157+
-- Cleanup
158+
DROP TABLE test_missing_target;
159+
-- DROP TABLE test_missing_target2;
160+
-- DROP TABLE test_missing_target3;

0 commit comments

Comments
 (0)