From f75eea52af5bc2796af3237c5d7ff623259d2608 Mon Sep 17 00:00:00 2001 From: Yuming Wang Date: Wed, 10 Jul 2019 16:08:57 +0800 Subject: [PATCH 1/6] Add select.sql --- .../sql-tests/inputs/pgSQL/select.sql | 269 ++++++++++++++++++ 1 file changed, 269 insertions(+) create mode 100644 sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql diff --git a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql new file mode 100644 index 0000000000000..ea5c07460193d --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql @@ -0,0 +1,269 @@ +-- +-- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group +-- +-- +-- SELECT +-- Test int8 64-bit integers. +-- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/select.sql +-- + +-- btree index +-- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1 +-- +SELECT * FROM onek + WHERE onek.unique1 < 10 + ORDER BY onek.unique1; + +-- +-- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 +-- +SELECT onek.unique1, onek.stringu1 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 using >; + +-- +-- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 +-- +SELECT onek.unique1, onek.stringu1 FROM onek + WHERE onek.unique1 > 980 + ORDER BY stringu1 using <; + +-- +-- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | +-- sort +1d -2 +0nr -1 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 > 980 + ORDER BY string4 using <, unique1 using >; + +-- +-- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | +-- sort +1dr -2 +0n -1 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 > 980 + ORDER BY string4 using >, unique1 using <; + +-- +-- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | +-- sort +0nr -1 +1d -2 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 using >, string4 using <; + +-- +-- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | +-- sort +0n -1 +1dr -2 +-- +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 using <, string4 using >; + +-- +-- test partial btree indexes +-- +-- As of 7.2, planner probably won't pick an indexscan without stats, +-- so ANALYZE first. Also, we want to prevent it from picking a bitmapscan +-- followed by sort, because that could hide index ordering problems. +-- +ANALYZE onek2; + +SET enable_seqscan TO off; +SET enable_bitmapscan TO off; +SET enable_sort TO off; + +-- +-- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1 +-- +SELECT onek2.* FROM onek2 WHERE onek2.unique1 < 10; + +-- +-- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 +-- +SELECT onek2.unique1, onek2.stringu1 FROM onek2 + WHERE onek2.unique1 < 20 + ORDER BY unique1 using >; + +-- +-- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 +-- +SELECT onek2.unique1, onek2.stringu1 FROM onek2 + WHERE onek2.unique1 > 980; + +RESET enable_seqscan; +RESET enable_bitmapscan; +RESET enable_sort; + + +SELECT two, stringu1, ten, string4 + INTO TABLE tmp + FROM onek; + +-- +-- awk '{print $1,$2;}' person.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - student.data | +-- awk 'BEGIN{FS=" ";}{if(NF!=2){print $4,$5;}else{print;}}' - stud_emp.data +-- +-- SELECT name, age FROM person*; ??? check if different +SELECT p.name, p.age FROM person* p; + +-- +-- awk '{print $1,$2;}' person.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data | +-- awk '{if(NF!=2){print $3,$2;}else{print;}}' - student.data | +-- awk 'BEGIN{FS=" ";}{if(NF!=1){print $4,$5;}else{print;}}' - stud_emp.data | +-- sort +1nr -2 +-- +SELECT p.name, p.age FROM person* p ORDER BY age using >, name; + +-- +-- Test some cases involving whole-row Var referencing a subquery +-- +select foo from (select 1 offset 0) as foo; +select foo from (select null offset 0) as foo; +select foo from (select 'xyzzy',1,null offset 0) as foo; + +-- +-- Test VALUES lists +-- +select * from onek, (values(147, 'RFAAAA'), (931, 'VJAAAA')) as v (i, j) + WHERE onek.unique1 = v.i and onek.stringu1 = v.j; + +-- a more complex case +-- looks like we're coding lisp :-) +select * from onek, + (values ((select i from + (values(10000), (2), (389), (1000), (2000), ((select 10029))) as foo(i) + order by i asc limit 1))) bar (i) + where onek.unique1 = bar.i; + +-- try VALUES in a subquery +select * from onek + where (unique1,ten) in (values (1,1), (20,0), (99,9), (17,99)) + order by unique1; + +-- VALUES is also legal as a standalone query or a set-operation member +VALUES (1,2), (3,4+4), (7,77.7); + +VALUES (1,2), (3,4+4), (7,77.7) +UNION ALL +SELECT 2+2, 57 +UNION ALL +TABLE int8_tbl; + +-- +-- Test ORDER BY options +-- + +CREATE TEMP TABLE foo (f1 int); + +INSERT INTO foo VALUES (42),(3),(10),(7),(null),(null),(1); + +SELECT * FROM foo ORDER BY f1; +SELECT * FROM foo ORDER BY f1 ASC; -- same thing +SELECT * FROM foo ORDER BY f1 NULLS FIRST; +SELECT * FROM foo ORDER BY f1 DESC; +SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; + +-- check if indexscans do the right things +CREATE INDEX fooi ON foo (f1); +SET enable_sort = false; + +SELECT * FROM foo ORDER BY f1; +SELECT * FROM foo ORDER BY f1 NULLS FIRST; +SELECT * FROM foo ORDER BY f1 DESC; +SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; + +DROP INDEX fooi; +CREATE INDEX fooi ON foo (f1 DESC); + +SELECT * FROM foo ORDER BY f1; +SELECT * FROM foo ORDER BY f1 NULLS FIRST; +SELECT * FROM foo ORDER BY f1 DESC; +SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; + +DROP INDEX fooi; +CREATE INDEX fooi ON foo (f1 DESC NULLS LAST); + +SELECT * FROM foo ORDER BY f1; +SELECT * FROM foo ORDER BY f1 NULLS FIRST; +SELECT * FROM foo ORDER BY f1 DESC; +SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; + +-- +-- Test planning of some cases with partial indexes +-- + +-- partial index is usable +explain (costs off) +select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +-- actually run the query with an analyze to use the partial index +explain (costs off, analyze on, timing off, summary off) +select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +explain (costs off) +select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +-- partial index predicate implies clause, so no need for retest +explain (costs off) +select * from onek2 where unique2 = 11 and stringu1 < 'B'; +select * from onek2 where unique2 = 11 and stringu1 < 'B'; +explain (costs off) +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; +-- but if it's an update target, must retest anyway +explain (costs off) +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update; +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update; +-- partial index is not applicable +explain (costs off) +select unique2 from onek2 where unique2 = 11 and stringu1 < 'C'; +select unique2 from onek2 where unique2 = 11 and stringu1 < 'C'; +-- partial index implies clause, but bitmap scan must recheck predicate anyway +SET enable_indexscan TO off; +explain (costs off) +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; +RESET enable_indexscan; +-- check multi-index cases too +explain (costs off) +select unique1, unique2 from onek2 + where (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; +select unique1, unique2 from onek2 + where (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; +explain (costs off) +select unique1, unique2 from onek2 + where (unique2 = 11 and stringu1 < 'B') or unique1 = 0; +select unique1, unique2 from onek2 + where (unique2 = 11 and stringu1 < 'B') or unique1 = 0; + +-- +-- Test some corner cases that have been known to confuse the planner +-- + +-- ORDER BY on a constant doesn't really need any sorting +SELECT 1 AS x ORDER BY x; + +-- But ORDER BY on a set-valued expression does +create function sillysrf(int) returns setof int as + 'values (1),(10),(2),($1)' language sql immutable; + +select sillysrf(42); +select sillysrf(-1) order by 1; + +drop function sillysrf(int); + +-- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict +-- (see bug #5084) +select * from (values (2),(null),(1)) v(k) where k = k order by k; +select * from (values (2),(null),(1)) v(k) where k = k; + +-- Test partitioned tables with no partitions, which should be handled the +-- same as the non-inheritance case when expanding its RTE. +create table list_parted_tbl (a int,b int) partition by list (a); +create table list_parted_tbl1 partition of list_parted_tbl + for values in (1) partition by list(b); +explain (costs off) select * from list_parted_tbl; +drop table list_parted_tbl; From f4344d9a5189ac2e61493ba2c4f6bae2285199ac Mon Sep 17 00:00:00 2001 From: Yuming Wang Date: Wed, 10 Jul 2019 19:49:38 +0800 Subject: [PATCH 2/6] Add result --- .../sql-tests/inputs/pgSQL/select.sql | 187 +++--- .../sql-tests/results/pgSQL/select.sql.out | 535 ++++++++++++++++++ 2 files changed, 635 insertions(+), 87 deletions(-) create mode 100644 sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out diff --git a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql index ea5c07460193d..986948344d97c 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql @@ -7,6 +7,14 @@ -- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/select.sql -- +create or replace temporary view INT8_TBL as select * from values + (cast(trim(' 123 ') as bigint), cast(trim(' 456') as bigint)), + (cast(trim('123 ') as bigint),cast('4567890123456789' as bigint)), + (cast('4567890123456789' as bigint),cast('123' as bigint)), + (cast(+4567890123456789 as bigint),cast('4567890123456789' as bigint)), + (cast('+4567890123456789' as bigint),cast('-4567890123456789' as bigint)) + as INT8_TBL(q1, q2); + -- btree index -- awk '{if($1<10){print;}else{next;}}' onek.data | sort +0n -1 -- @@ -14,19 +22,20 @@ SELECT * FROM onek WHERE onek.unique1 < 10 ORDER BY onek.unique1; +-- [SPARK-28010] Support ORDER BY ... USING syntax -- -- awk '{if($1<20){print $1,$14;}else{next;}}' onek.data | sort +0nr -1 -- SELECT onek.unique1, onek.stringu1 FROM onek WHERE onek.unique1 < 20 - ORDER BY unique1 using >; + ORDER BY unique1 DESC; -- -- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 -- SELECT onek.unique1, onek.stringu1 FROM onek WHERE onek.unique1 > 980 - ORDER BY stringu1 using <; + ORDER BY stringu1 ASC; -- -- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | @@ -34,7 +43,7 @@ SELECT onek.unique1, onek.stringu1 FROM onek -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 > 980 - ORDER BY string4 using <, unique1 using >; + ORDER BY string4 ASC, unique1 DESC; -- -- awk '{if($1>980){print $1,$16;}else{next;}}' onek.data | @@ -42,7 +51,7 @@ SELECT onek.unique1, onek.string4 FROM onek -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 > 980 - ORDER BY string4 using >, unique1 using <; + ORDER BY string4 DESC, unique1 ASC; -- -- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | @@ -50,7 +59,7 @@ SELECT onek.unique1, onek.string4 FROM onek -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 < 20 - ORDER BY unique1 using >, string4 using <; + ORDER BY unique1 DESC, string4 ASC; -- -- awk '{if($1<20){print $1,$16;}else{next;}}' onek.data | @@ -58,7 +67,7 @@ SELECT onek.unique1, onek.string4 FROM onek -- SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 < 20 - ORDER BY unique1 using <, string4 using >; + ORDER BY unique1 ASC, string4 DESC; -- -- test partial btree indexes @@ -67,11 +76,11 @@ SELECT onek.unique1, onek.string4 FROM onek -- so ANALYZE first. Also, we want to prevent it from picking a bitmapscan -- followed by sort, because that could hide index ordering problems. -- -ANALYZE onek2; +-- ANALYZE onek2; -SET enable_seqscan TO off; -SET enable_bitmapscan TO off; -SET enable_sort TO off; +-- SET enable_seqscan TO off; +-- SET enable_bitmapscan TO off; +-- SET enable_sort TO off; -- -- awk '{if($1<10){print $0;}else{next;}}' onek.data | sort +0n -1 @@ -83,7 +92,7 @@ SELECT onek2.* FROM onek2 WHERE onek2.unique1 < 10; -- SELECT onek2.unique1, onek2.stringu1 FROM onek2 WHERE onek2.unique1 < 20 - ORDER BY unique1 using >; + ORDER BY unique1 DESC; -- -- awk '{if($1>980){print $1,$14;}else{next;}}' onek.data | sort +1d -2 @@ -91,15 +100,16 @@ SELECT onek2.unique1, onek2.stringu1 FROM onek2 SELECT onek2.unique1, onek2.stringu1 FROM onek2 WHERE onek2.unique1 > 980; -RESET enable_seqscan; -RESET enable_bitmapscan; -RESET enable_sort; - +-- RESET enable_seqscan; +-- RESET enable_bitmapscan; +-- RESET enable_sort; +-- [SPARK-28329] SELECT INTO syntax +CREATE TABLE tmp USING parquet AS SELECT two, stringu1, ten, string4 - INTO TABLE tmp - FROM onek; +FROM onek; +-- Skip the person table because there is a point data type that we don't support. -- -- awk '{print $1,$2;}' person.data | -- awk '{if(NF!=2){print $3,$2;}else{print;}}' - emp.data | @@ -107,7 +117,7 @@ SELECT two, stringu1, ten, string4 -- awk 'BEGIN{FS=" ";}{if(NF!=2){print $4,$5;}else{print;}}' - stud_emp.data -- -- SELECT name, age FROM person*; ??? check if different -SELECT p.name, p.age FROM person* p; +-- SELECT p.name, p.age FROM person* p; -- -- awk '{print $1,$2;}' person.data | @@ -116,33 +126,35 @@ SELECT p.name, p.age FROM person* p; -- awk 'BEGIN{FS=" ";}{if(NF!=1){print $4,$5;}else{print;}}' - stud_emp.data | -- sort +1nr -2 -- -SELECT p.name, p.age FROM person* p ORDER BY age using >, name; +-- SELECT p.name, p.age FROM person* p ORDER BY age DESC, name; +-- [SPARK-28330] Enhance query limit -- -- Test some cases involving whole-row Var referencing a subquery -- -select foo from (select 1 offset 0) as foo; -select foo from (select null offset 0) as foo; -select foo from (select 'xyzzy',1,null offset 0) as foo; +select foo.* from (select 1) as foo; +select foo.* from (select null) as foo; +select foo.* from (select 'xyzzy',1,null) as foo; -- -- Test VALUES lists -- -select * from onek, (values(147, 'RFAAAA'), (931, 'VJAAAA')) as v (i, j) +select * from onek, values(147, 'RFAAAA'), (931, 'VJAAAA') as v (i, j) WHERE onek.unique1 = v.i and onek.stringu1 = v.j; +-- [SPARK-28296] Improved VALUES support -- a more complex case -- looks like we're coding lisp :-) -select * from onek, - (values ((select i from - (values(10000), (2), (389), (1000), (2000), ((select 10029))) as foo(i) - order by i asc limit 1))) bar (i) - where onek.unique1 = bar.i; +-- select * from onek, +-- (values ((select i from +-- (values(10000), (2), (389), (1000), (2000), ((select 10029))) as foo(i) +-- order by i asc limit 1))) bar (i) +-- where onek.unique1 = bar.i; -- try VALUES in a subquery -select * from onek - where (unique1,ten) in (values (1,1), (20,0), (99,9), (17,99)) - order by unique1; +-- select * from onek +-- where (unique1,ten) in (values (1,1), (20,0), (99,9), (17,99)) +-- order by unique1; -- VALUES is also legal as a standalone query or a set-operation member VALUES (1,2), (3,4+4), (7,77.7); @@ -157,10 +169,10 @@ TABLE int8_tbl; -- Test ORDER BY options -- -CREATE TEMP TABLE foo (f1 int); - -INSERT INTO foo VALUES (42),(3),(10),(7),(null),(null),(1); +CREATE OR REPLACE TEMPORARY VIEW foo AS +SELECT * FROM (values(42),(3),(10),(7),(null),(null),(1)) as foo (f1); +-- [SPARK-28333] NULLS FIRST for DESC and NULLS LAST for ASC SELECT * FROM foo ORDER BY f1; SELECT * FROM foo ORDER BY f1 ASC; -- same thing SELECT * FROM foo ORDER BY f1 NULLS FIRST; @@ -168,74 +180,74 @@ SELECT * FROM foo ORDER BY f1 DESC; SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; -- check if indexscans do the right things -CREATE INDEX fooi ON foo (f1); -SET enable_sort = false; +-- CREATE INDEX fooi ON foo (f1); +-- SET enable_sort = false; -SELECT * FROM foo ORDER BY f1; -SELECT * FROM foo ORDER BY f1 NULLS FIRST; -SELECT * FROM foo ORDER BY f1 DESC; -SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- SELECT * FROM foo ORDER BY f1; +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- SELECT * FROM foo ORDER BY f1 DESC; +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; -DROP INDEX fooi; -CREATE INDEX fooi ON foo (f1 DESC); +-- DROP INDEX fooi; +-- CREATE INDEX fooi ON foo (f1 DESC); -SELECT * FROM foo ORDER BY f1; -SELECT * FROM foo ORDER BY f1 NULLS FIRST; -SELECT * FROM foo ORDER BY f1 DESC; -SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- SELECT * FROM foo ORDER BY f1; +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- SELECT * FROM foo ORDER BY f1 DESC; +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; -DROP INDEX fooi; -CREATE INDEX fooi ON foo (f1 DESC NULLS LAST); +-- DROP INDEX fooi; +-- CREATE INDEX fooi ON foo (f1 DESC NULLS LAST); -SELECT * FROM foo ORDER BY f1; -SELECT * FROM foo ORDER BY f1 NULLS FIRST; -SELECT * FROM foo ORDER BY f1 DESC; -SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; +-- SELECT * FROM foo ORDER BY f1; +-- SELECT * FROM foo ORDER BY f1 NULLS FIRST; +-- SELECT * FROM foo ORDER BY f1 DESC; +-- SELECT * FROM foo ORDER BY f1 DESC NULLS LAST; -- -- Test planning of some cases with partial indexes -- -- partial index is usable -explain (costs off) -select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +-- explain (costs off) +-- select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; -- actually run the query with an analyze to use the partial index -explain (costs off, analyze on, timing off, summary off) -select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; -explain (costs off) -select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +-- explain (costs off, analyze on, timing off, summary off) +-- select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; +-- explain (costs off) +-- select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA'; -- partial index predicate implies clause, so no need for retest -explain (costs off) -select * from onek2 where unique2 = 11 and stringu1 < 'B'; +-- explain (costs off) +-- select * from onek2 where unique2 = 11 and stringu1 < 'B'; select * from onek2 where unique2 = 11 and stringu1 < 'B'; -explain (costs off) -select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; +-- explain (costs off) +-- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; -- but if it's an update target, must retest anyway -explain (costs off) -select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update; -select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update; +-- explain (costs off) +-- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update; +-- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' for update; -- partial index is not applicable -explain (costs off) -select unique2 from onek2 where unique2 = 11 and stringu1 < 'C'; +-- explain (costs off) +-- select unique2 from onek2 where unique2 = 11 and stringu1 < 'C'; select unique2 from onek2 where unique2 = 11 and stringu1 < 'C'; -- partial index implies clause, but bitmap scan must recheck predicate anyway -SET enable_indexscan TO off; -explain (costs off) -select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; +-- SET enable_indexscan TO off; +-- explain (costs off) +-- select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; select unique2 from onek2 where unique2 = 11 and stringu1 < 'B'; -RESET enable_indexscan; +-- RESET enable_indexscan; -- check multi-index cases too -explain (costs off) -select unique1, unique2 from onek2 - where (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; +-- explain (costs off) +-- select unique1, unique2 from onek2 +-- where (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; select unique1, unique2 from onek2 where (unique2 = 11 or unique1 = 0) and stringu1 < 'B'; -explain (costs off) -select unique1, unique2 from onek2 - where (unique2 = 11 and stringu1 < 'B') or unique1 = 0; +-- explain (costs off) +-- select unique1, unique2 from onek2 +-- where (unique2 = 11 and stringu1 < 'B') or unique1 = 0; select unique1, unique2 from onek2 where (unique2 = 11 and stringu1 < 'B') or unique1 = 0; @@ -247,13 +259,13 @@ select unique1, unique2 from onek2 SELECT 1 AS x ORDER BY x; -- But ORDER BY on a set-valued expression does -create function sillysrf(int) returns setof int as - 'values (1),(10),(2),($1)' language sql immutable; +-- create function sillysrf(int) returns setof int as +-- 'values (1),(10),(2),($1)' language sql immutable; -select sillysrf(42); -select sillysrf(-1) order by 1; +-- select sillysrf(42); +-- select sillysrf(-1) order by 1; -drop function sillysrf(int); +-- drop function sillysrf(int); -- X = X isn't a no-op, it's effectively X IS NOT NULL assuming = is strict -- (see bug #5084) @@ -262,8 +274,9 @@ select * from (values (2),(null),(1)) v(k) where k = k; -- Test partitioned tables with no partitions, which should be handled the -- same as the non-inheritance case when expanding its RTE. -create table list_parted_tbl (a int,b int) partition by list (a); -create table list_parted_tbl1 partition of list_parted_tbl - for values in (1) partition by list(b); -explain (costs off) select * from list_parted_tbl; -drop table list_parted_tbl; +-- create table list_parted_tbl (a int,b int) partition by list (a); +-- create table list_parted_tbl1 partition of list_parted_tbl +-- for values in (1) partition by list(b); +-- explain (costs off) select * from list_parted_tbl; +-- drop table list_parted_tbl; +drop table tmp; diff --git a/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out b/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out new file mode 100644 index 0000000000000..11c893cccd8d4 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out @@ -0,0 +1,535 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 36 + + +-- !query 0 +create or replace temporary view INT8_TBL as select * from values + (cast(trim(' 123 ') as bigint), cast(trim(' 456') as bigint)), + (cast(trim('123 ') as bigint),cast('4567890123456789' as bigint)), + (cast('4567890123456789' as bigint),cast('123' as bigint)), + (cast(+4567890123456789 as bigint),cast('4567890123456789' as bigint)), + (cast('+4567890123456789' as bigint),cast('-4567890123456789' as bigint)) + as INT8_TBL(q1, q2) +-- !query 0 schema +struct<> +-- !query 0 output + + + +-- !query 1 +SELECT * FROM onek + WHERE onek.unique1 < 10 + ORDER BY onek.unique1 +-- !query 1 schema +struct +-- !query 1 output +0 998 0 0 0 0 0 0 0 0 0 0 1 AAAAAA KMBAAA OOOOxx +1 214 1 1 1 1 1 1 1 1 1 2 3 BAAAAA GIAAAA OOOOxx +2 326 0 2 2 2 2 2 2 2 2 4 5 CAAAAA OMAAAA OOOOxx +3 431 1 3 3 3 3 3 3 3 3 6 7 DAAAAA PQAAAA VVVVxx +4 833 0 0 4 4 4 4 4 4 4 8 9 EAAAAA BGBAAA HHHHxx +5 541 1 1 5 5 5 5 5 5 5 10 11 FAAAAA VUAAAA HHHHxx +6 978 0 2 6 6 6 6 6 6 6 12 13 GAAAAA QLBAAA OOOOxx +7 647 1 3 7 7 7 7 7 7 7 14 15 HAAAAA XYAAAA VVVVxx +8 653 0 0 8 8 8 8 8 8 8 16 17 IAAAAA DZAAAA HHHHxx +9 49 1 1 9 9 9 9 9 9 9 18 19 JAAAAA XBAAAA HHHHxx + + +-- !query 2 +SELECT onek.unique1, onek.stringu1 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 DESC +-- !query 2 schema +struct +-- !query 2 output +19 TAAAAA +18 SAAAAA +17 RAAAAA +16 QAAAAA +15 PAAAAA +14 OAAAAA +13 NAAAAA +12 MAAAAA +11 LAAAAA +10 KAAAAA +9 JAAAAA +8 IAAAAA +7 HAAAAA +6 GAAAAA +5 FAAAAA +4 EAAAAA +3 DAAAAA +2 CAAAAA +1 BAAAAA +0 AAAAAA + + +-- !query 3 +SELECT onek.unique1, onek.stringu1 FROM onek + WHERE onek.unique1 > 980 + ORDER BY stringu1 ASC +-- !query 3 schema +struct +-- !query 3 output +988 AMAAAA +989 BMAAAA +990 CMAAAA +991 DMAAAA +992 EMAAAA +993 FMAAAA +994 GMAAAA +995 HMAAAA +996 IMAAAA +997 JMAAAA +998 KMAAAA +999 LMAAAA +981 TLAAAA +982 ULAAAA +983 VLAAAA +984 WLAAAA +985 XLAAAA +986 YLAAAA +987 ZLAAAA + + +-- !query 4 +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 > 980 + ORDER BY string4 ASC, unique1 DESC +-- !query 4 schema +struct +-- !query 4 output +999 AAAAxx +995 AAAAxx +983 AAAAxx +982 AAAAxx +981 AAAAxx +998 HHHHxx +997 HHHHxx +993 HHHHxx +990 HHHHxx +986 HHHHxx +996 OOOOxx +991 OOOOxx +988 OOOOxx +987 OOOOxx +985 OOOOxx +994 VVVVxx +992 VVVVxx +989 VVVVxx +984 VVVVxx + + +-- !query 5 +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 > 980 + ORDER BY string4 DESC, unique1 ASC +-- !query 5 schema +struct +-- !query 5 output +984 VVVVxx +989 VVVVxx +992 VVVVxx +994 VVVVxx +985 OOOOxx +987 OOOOxx +988 OOOOxx +991 OOOOxx +996 OOOOxx +986 HHHHxx +990 HHHHxx +993 HHHHxx +997 HHHHxx +998 HHHHxx +981 AAAAxx +982 AAAAxx +983 AAAAxx +995 AAAAxx +999 AAAAxx + + +-- !query 6 +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 DESC, string4 ASC +-- !query 6 schema +struct +-- !query 6 output +19 OOOOxx +18 VVVVxx +17 HHHHxx +16 OOOOxx +15 VVVVxx +14 AAAAxx +13 OOOOxx +12 AAAAxx +11 OOOOxx +10 AAAAxx +9 HHHHxx +8 HHHHxx +7 VVVVxx +6 OOOOxx +5 HHHHxx +4 HHHHxx +3 VVVVxx +2 OOOOxx +1 OOOOxx +0 OOOOxx + + +-- !query 7 +SELECT onek.unique1, onek.string4 FROM onek + WHERE onek.unique1 < 20 + ORDER BY unique1 ASC, string4 DESC +-- !query 7 schema +struct +-- !query 7 output +0 OOOOxx +1 OOOOxx +2 OOOOxx +3 VVVVxx +4 HHHHxx +5 HHHHxx +6 OOOOxx +7 VVVVxx +8 HHHHxx +9 HHHHxx +10 AAAAxx +11 OOOOxx +12 AAAAxx +13 OOOOxx +14 AAAAxx +15 VVVVxx +16 OOOOxx +17 HHHHxx +18 VVVVxx +19 OOOOxx + + +-- !query 8 +SELECT onek2.* FROM onek2 WHERE onek2.unique1 < 10 +-- !query 8 schema +struct +-- !query 8 output +0 998 0 0 0 0 0 0 0 0 0 0 1 AAAAAA KMBAAA OOOOxx +1 214 1 1 1 1 1 1 1 1 1 2 3 BAAAAA GIAAAA OOOOxx +2 326 0 2 2 2 2 2 2 2 2 4 5 CAAAAA OMAAAA OOOOxx +3 431 1 3 3 3 3 3 3 3 3 6 7 DAAAAA PQAAAA VVVVxx +4 833 0 0 4 4 4 4 4 4 4 8 9 EAAAAA BGBAAA HHHHxx +5 541 1 1 5 5 5 5 5 5 5 10 11 FAAAAA VUAAAA HHHHxx +6 978 0 2 6 6 6 6 6 6 6 12 13 GAAAAA QLBAAA OOOOxx +7 647 1 3 7 7 7 7 7 7 7 14 15 HAAAAA XYAAAA VVVVxx +8 653 0 0 8 8 8 8 8 8 8 16 17 IAAAAA DZAAAA HHHHxx +9 49 1 1 9 9 9 9 9 9 9 18 19 JAAAAA XBAAAA HHHHxx + + +-- !query 9 +SELECT onek2.unique1, onek2.stringu1 FROM onek2 + WHERE onek2.unique1 < 20 + ORDER BY unique1 DESC +-- !query 9 schema +struct +-- !query 9 output +19 TAAAAA +18 SAAAAA +17 RAAAAA +16 QAAAAA +15 PAAAAA +14 OAAAAA +13 NAAAAA +12 MAAAAA +11 LAAAAA +10 KAAAAA +9 JAAAAA +8 IAAAAA +7 HAAAAA +6 GAAAAA +5 FAAAAA +4 EAAAAA +3 DAAAAA +2 CAAAAA +1 BAAAAA +0 AAAAAA + + +-- !query 10 +SELECT onek2.unique1, onek2.stringu1 FROM onek2 + WHERE onek2.unique1 > 980 +-- !query 10 schema +struct +-- !query 10 output +981 TLAAAA +982 ULAAAA +983 VLAAAA +984 WLAAAA +985 XLAAAA +986 YLAAAA +987 ZLAAAA +988 AMAAAA +989 BMAAAA +990 CMAAAA +991 DMAAAA +992 EMAAAA +993 FMAAAA +994 GMAAAA +995 HMAAAA +996 IMAAAA +997 JMAAAA +998 KMAAAA +999 LMAAAA + + +-- !query 11 +CREATE TABLE tmp USING parquet AS +SELECT two, stringu1, ten, string4 +FROM onek +-- !query 11 schema +struct<> +-- !query 11 output + + + +-- !query 12 +select foo.* from (select 1) as foo +-- !query 12 schema +struct<1:int> +-- !query 12 output +1 + + +-- !query 13 +select foo.* from (select null) as foo +-- !query 13 schema +struct +-- !query 13 output +NULL + + +-- !query 14 +select foo.* from (select 'xyzzy',1,null) as foo +-- !query 14 schema +struct +-- !query 14 output +xyzzy 1 NULL + + +-- !query 15 +select * from onek, values(147, 'RFAAAA'), (931, 'VJAAAA') as v (i, j) + WHERE onek.unique1 = v.i and onek.stringu1 = v.j +-- !query 15 schema +struct +-- !query 15 output +147 0 1 3 7 7 7 47 147 147 147 14 15 RFAAAA AAAAAA AAAAxx 147 RFAAAA +931 1 1 3 1 11 1 31 131 431 931 2 3 VJAAAA BAAAAA HHHHxx 931 VJAAAA + + +-- !query 16 +VALUES (1,2), (3,4+4), (7,77.7) +-- !query 16 schema +struct +-- !query 16 output +1 2 +3 8 +7 77.7 + + +-- !query 17 +VALUES (1,2), (3,4+4), (7,77.7) +UNION ALL +SELECT 2+2, 57 +UNION ALL +TABLE int8_tbl +-- !query 17 schema +struct +-- !query 17 output +1 2 +123 456 +123 4567890123456789 +3 8 +4 57 +4567890123456789 -4567890123456789 +4567890123456789 123 +4567890123456789 4567890123456789 +7 77.7 + + +-- !query 18 +CREATE OR REPLACE TEMPORARY VIEW foo AS +SELECT * FROM (values(42),(3),(10),(7),(null),(null),(1)) as foo (f1) +-- !query 18 schema +struct<> +-- !query 18 output + + + +-- !query 19 +SELECT * FROM foo ORDER BY f1 +-- !query 19 schema +struct +-- !query 19 output +NULL +NULL +1 +3 +7 +10 +42 + + +-- !query 20 +SELECT * FROM foo ORDER BY f1 ASC +-- !query 20 schema +struct +-- !query 20 output +NULL +NULL +1 +3 +7 +10 +42 + + +-- !query 21 +-- same thing +SELECT * FROM foo ORDER BY f1 NULLS FIRST +-- !query 21 schema +struct +-- !query 21 output +NULL +NULL +1 +3 +7 +10 +42 + + +-- !query 22 +SELECT * FROM foo ORDER BY f1 DESC +-- !query 22 schema +struct +-- !query 22 output +42 +10 +7 +3 +1 +NULL +NULL + + +-- !query 23 +SELECT * FROM foo ORDER BY f1 DESC NULLS LAST +-- !query 23 schema +struct +-- !query 23 output +42 +10 +7 +3 +1 +NULL +NULL + + +-- !query 24 +select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA' +-- !query 24 schema +struct +-- !query 24 output +494 11 0 2 4 14 4 94 94 494 494 8 9 ATAAAA LAAAAA VVVVxx + + +-- !query 25 +select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA' +-- !query 25 schema +struct +-- !query 25 output +11 + + +-- !query 26 +select * from onek2 where unique2 = 11 and stringu1 < 'B' +-- !query 26 schema +struct +-- !query 26 output +494 11 0 2 4 14 4 94 94 494 494 8 9 ATAAAA LAAAAA VVVVxx + + +-- !query 27 +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' +-- !query 27 schema +struct +-- !query 27 output +11 + + +-- !query 28 +select unique2 from onek2 where unique2 = 11 and stringu1 < 'C' +-- !query 28 schema +struct +-- !query 28 output +11 + + +-- !query 29 +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' +-- !query 29 schema +struct +-- !query 29 output +11 + + +-- !query 30 +select unique1, unique2 from onek2 + where (unique2 = 11 or unique1 = 0) and stringu1 < 'B' +-- !query 30 schema +struct +-- !query 30 output +0 998 +494 11 + + +-- !query 31 +select unique1, unique2 from onek2 + where (unique2 = 11 and stringu1 < 'B') or unique1 = 0 +-- !query 31 schema +struct +-- !query 31 output +0 998 +494 11 + + +-- !query 32 +SELECT 1 AS x ORDER BY x +-- !query 32 schema +struct +-- !query 32 output +1 + + +-- !query 33 +select * from (values (2),(null),(1)) v(k) where k = k order by k +-- !query 33 schema +struct +-- !query 33 output +1 +2 + + +-- !query 34 +select * from (values (2),(null),(1)) v(k) where k = k +-- !query 34 schema +struct +-- !query 34 output +1 +2 + + +-- !query 35 +drop table tmp +-- !query 35 schema +struct<> +-- !query 35 output + From 767c677402b550887288e68a15dc54c8f9193655 Mon Sep 17 00:00:00 2001 From: Yuming Wang Date: Wed, 10 Jul 2019 19:56:13 +0800 Subject: [PATCH 3/6] Update SQLQueryTestSuite --- .../apache/spark/sql/SQLQueryTestSuite.scala | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala index c8a187b57a610..ba183f9d3cc42 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala @@ -487,6 +487,32 @@ class SQLQueryTestSuite extends QueryTest with SharedSQLContext { """.stripMargin) .load(testFile("test-data/postgresql/tenk.data")) .createOrReplaceTempView("tenk1") + + session + .read + .format("csv") + .options(Map("delimiter" -> "\t", "header" -> "false")) + .schema( + """ + |unique1 int, + |unique2 int, + |two int, + |four int, + |ten int, + |twenty int, + |hundred int, + |thousand int, + |twothousand int, + |fivethous int, + |tenthous int, + |odd int, + |even int, + |stringu1 string, + |stringu2 string, + |string4 string + """.stripMargin) + .load(testFile("test-data/postgresql/onek.data")) + .createOrReplaceTempView("onek2") } private val originalTimeZone = TimeZone.getDefault From c655e586234588be05f0eeee9a317e6df04d03ee Mon Sep 17 00:00:00 2001 From: Yuming Wang Date: Wed, 10 Jul 2019 23:30:51 +0800 Subject: [PATCH 4/6] Fix test error --- .../src/test/resources/sql-tests/results/show-tables.sql.out | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out b/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out index 8efeae3a1bd09..c05a33a5e5ece 100644 --- a/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out @@ -67,6 +67,7 @@ aggtest arraydata mapdata onek +onek2 show_t1 show_t2 show_t3 @@ -83,6 +84,7 @@ aggtest arraydata mapdata onek +onek2 show_t1 show_t2 show_t3 From 7aa7d49b020beb657dfa3e6a79c9240aba5e4e00 Mon Sep 17 00:00:00 2001 From: Yuming Wang Date: Thu, 11 Jul 2019 07:22:10 +0800 Subject: [PATCH 5/6] Move create onek2 from SQLQueryTestSuite to select.sql --- .../sql-tests/inputs/pgSQL/select.sql | 2 +- .../sql-tests/results/pgSQL/select.sql.out | 220 +++++++++--------- .../sql-tests/results/show-tables.sql.out | 2 - .../apache/spark/sql/SQLQueryTestSuite.scala | 26 --- 4 files changed, 115 insertions(+), 135 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql index 986948344d97c..e4e9ca932f810 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql @@ -6,7 +6,7 @@ -- Test int8 64-bit integers. -- https://github.com/postgres/postgres/blob/REL_12_BETA2/src/test/regress/sql/select.sql -- - +create or replace temporary view onek2 as select * from onek; create or replace temporary view INT8_TBL as select * from values (cast(trim(' 123 ') as bigint), cast(trim(' 456') as bigint)), (cast(trim('123 ') as bigint),cast('4567890123456789' as bigint)), diff --git a/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out b/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out index 11c893cccd8d4..797f808dad11e 100644 --- a/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/pgSQL/select.sql.out @@ -1,8 +1,16 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 36 +-- Number of queries: 37 -- !query 0 +create or replace temporary view onek2 as select * from onek +-- !query 0 schema +struct<> +-- !query 0 output + + + +-- !query 1 create or replace temporary view INT8_TBL as select * from values (cast(trim(' 123 ') as bigint), cast(trim(' 456') as bigint)), (cast(trim('123 ') as bigint),cast('4567890123456789' as bigint)), @@ -10,19 +18,19 @@ create or replace temporary view INT8_TBL as select * from values (cast(+4567890123456789 as bigint),cast('4567890123456789' as bigint)), (cast('+4567890123456789' as bigint),cast('-4567890123456789' as bigint)) as INT8_TBL(q1, q2) --- !query 0 schema +-- !query 1 schema struct<> --- !query 0 output +-- !query 1 output --- !query 1 +-- !query 2 SELECT * FROM onek WHERE onek.unique1 < 10 ORDER BY onek.unique1 --- !query 1 schema +-- !query 2 schema struct --- !query 1 output +-- !query 2 output 0 998 0 0 0 0 0 0 0 0 0 0 1 AAAAAA KMBAAA OOOOxx 1 214 1 1 1 1 1 1 1 1 1 2 3 BAAAAA GIAAAA OOOOxx 2 326 0 2 2 2 2 2 2 2 2 4 5 CAAAAA OMAAAA OOOOxx @@ -35,13 +43,13 @@ struct --- !query 2 output +-- !query 3 output 19 TAAAAA 18 SAAAAA 17 RAAAAA @@ -64,13 +72,13 @@ struct 0 AAAAAA --- !query 3 +-- !query 4 SELECT onek.unique1, onek.stringu1 FROM onek WHERE onek.unique1 > 980 ORDER BY stringu1 ASC --- !query 3 schema +-- !query 4 schema struct --- !query 3 output +-- !query 4 output 988 AMAAAA 989 BMAAAA 990 CMAAAA @@ -92,13 +100,13 @@ struct 987 ZLAAAA --- !query 4 +-- !query 5 SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 > 980 ORDER BY string4 ASC, unique1 DESC --- !query 4 schema +-- !query 5 schema struct --- !query 4 output +-- !query 5 output 999 AAAAxx 995 AAAAxx 983 AAAAxx @@ -120,13 +128,13 @@ struct 984 VVVVxx --- !query 5 +-- !query 6 SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 > 980 ORDER BY string4 DESC, unique1 ASC --- !query 5 schema +-- !query 6 schema struct --- !query 5 output +-- !query 6 output 984 VVVVxx 989 VVVVxx 992 VVVVxx @@ -148,13 +156,13 @@ struct 999 AAAAxx --- !query 6 +-- !query 7 SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 < 20 ORDER BY unique1 DESC, string4 ASC --- !query 6 schema +-- !query 7 schema struct --- !query 6 output +-- !query 7 output 19 OOOOxx 18 VVVVxx 17 HHHHxx @@ -177,13 +185,13 @@ struct 0 OOOOxx --- !query 7 +-- !query 8 SELECT onek.unique1, onek.string4 FROM onek WHERE onek.unique1 < 20 ORDER BY unique1 ASC, string4 DESC --- !query 7 schema +-- !query 8 schema struct --- !query 7 output +-- !query 8 output 0 OOOOxx 1 OOOOxx 2 OOOOxx @@ -206,11 +214,11 @@ struct 19 OOOOxx --- !query 8 +-- !query 9 SELECT onek2.* FROM onek2 WHERE onek2.unique1 < 10 --- !query 8 schema +-- !query 9 schema struct --- !query 8 output +-- !query 9 output 0 998 0 0 0 0 0 0 0 0 0 0 1 AAAAAA KMBAAA OOOOxx 1 214 1 1 1 1 1 1 1 1 1 2 3 BAAAAA GIAAAA OOOOxx 2 326 0 2 2 2 2 2 2 2 2 4 5 CAAAAA OMAAAA OOOOxx @@ -223,13 +231,13 @@ struct --- !query 9 output +-- !query 10 output 19 TAAAAA 18 SAAAAA 17 RAAAAA @@ -252,12 +260,12 @@ struct 0 AAAAAA --- !query 10 +-- !query 11 SELECT onek2.unique1, onek2.stringu1 FROM onek2 WHERE onek2.unique1 > 980 --- !query 10 schema +-- !query 11 schema struct --- !query 10 output +-- !query 11 output 981 TLAAAA 982 ULAAAA 983 VLAAAA @@ -279,69 +287,69 @@ struct 999 LMAAAA --- !query 11 +-- !query 12 CREATE TABLE tmp USING parquet AS SELECT two, stringu1, ten, string4 FROM onek --- !query 11 schema +-- !query 12 schema struct<> --- !query 11 output +-- !query 12 output --- !query 12 +-- !query 13 select foo.* from (select 1) as foo --- !query 12 schema +-- !query 13 schema struct<1:int> --- !query 12 output +-- !query 13 output 1 --- !query 13 +-- !query 14 select foo.* from (select null) as foo --- !query 13 schema +-- !query 14 schema struct --- !query 13 output +-- !query 14 output NULL --- !query 14 +-- !query 15 select foo.* from (select 'xyzzy',1,null) as foo --- !query 14 schema +-- !query 15 schema struct --- !query 14 output +-- !query 15 output xyzzy 1 NULL --- !query 15 +-- !query 16 select * from onek, values(147, 'RFAAAA'), (931, 'VJAAAA') as v (i, j) WHERE onek.unique1 = v.i and onek.stringu1 = v.j --- !query 15 schema +-- !query 16 schema struct --- !query 15 output +-- !query 16 output 147 0 1 3 7 7 7 47 147 147 147 14 15 RFAAAA AAAAAA AAAAxx 147 RFAAAA 931 1 1 3 1 11 1 31 131 431 931 2 3 VJAAAA BAAAAA HHHHxx 931 VJAAAA --- !query 16 +-- !query 17 VALUES (1,2), (3,4+4), (7,77.7) --- !query 16 schema +-- !query 17 schema struct --- !query 16 output +-- !query 17 output 1 2 3 8 7 77.7 --- !query 17 +-- !query 18 VALUES (1,2), (3,4+4), (7,77.7) UNION ALL SELECT 2+2, 57 UNION ALL TABLE int8_tbl --- !query 17 schema +-- !query 18 schema struct --- !query 17 output +-- !query 18 output 1 2 123 456 123 4567890123456789 @@ -353,20 +361,20 @@ struct 7 77.7 --- !query 18 +-- !query 19 CREATE OR REPLACE TEMPORARY VIEW foo AS SELECT * FROM (values(42),(3),(10),(7),(null),(null),(1)) as foo (f1) --- !query 18 schema +-- !query 19 schema struct<> --- !query 18 output +-- !query 19 output --- !query 19 +-- !query 20 SELECT * FROM foo ORDER BY f1 --- !query 19 schema +-- !query 20 schema struct --- !query 19 output +-- !query 20 output NULL NULL 1 @@ -376,11 +384,11 @@ NULL 42 --- !query 20 +-- !query 21 SELECT * FROM foo ORDER BY f1 ASC --- !query 20 schema +-- !query 21 schema struct --- !query 20 output +-- !query 21 output NULL NULL 1 @@ -390,12 +398,12 @@ NULL 42 --- !query 21 +-- !query 22 -- same thing SELECT * FROM foo ORDER BY f1 NULLS FIRST --- !query 21 schema +-- !query 22 schema struct --- !query 21 output +-- !query 22 output NULL NULL 1 @@ -405,11 +413,11 @@ NULL 42 --- !query 22 +-- !query 23 SELECT * FROM foo ORDER BY f1 DESC --- !query 22 schema +-- !query 23 schema struct --- !query 22 output +-- !query 23 output 42 10 7 @@ -419,11 +427,11 @@ NULL NULL --- !query 23 +-- !query 24 SELECT * FROM foo ORDER BY f1 DESC NULLS LAST --- !query 23 schema +-- !query 24 schema struct --- !query 23 output +-- !query 24 output 42 10 7 @@ -433,40 +441,32 @@ NULL NULL --- !query 24 -select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA' --- !query 24 schema -struct --- !query 24 output -494 11 0 2 4 14 4 94 94 494 494 8 9 ATAAAA LAAAAA VVVVxx - - -- !query 25 -select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA' +select * from onek2 where unique2 = 11 and stringu1 = 'ATAAAA' -- !query 25 schema -struct +struct -- !query 25 output -11 +494 11 0 2 4 14 4 94 94 494 494 8 9 ATAAAA LAAAAA VVVVxx -- !query 26 -select * from onek2 where unique2 = 11 and stringu1 < 'B' +select unique2 from onek2 where unique2 = 11 and stringu1 = 'ATAAAA' -- !query 26 schema -struct +struct -- !query 26 output -494 11 0 2 4 14 4 94 94 494 494 8 9 ATAAAA LAAAAA VVVVxx +11 -- !query 27 -select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' +select * from onek2 where unique2 = 11 and stringu1 < 'B' -- !query 27 schema -struct +struct -- !query 27 output -11 +494 11 0 2 4 14 4 94 94 494 494 8 9 ATAAAA LAAAAA VVVVxx -- !query 28 -select unique2 from onek2 where unique2 = 11 and stringu1 < 'C' +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' -- !query 28 schema struct -- !query 28 output @@ -474,7 +474,7 @@ struct -- !query 29 -select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' +select unique2 from onek2 where unique2 = 11 and stringu1 < 'C' -- !query 29 schema struct -- !query 29 output @@ -482,18 +482,16 @@ struct -- !query 30 -select unique1, unique2 from onek2 - where (unique2 = 11 or unique1 = 0) and stringu1 < 'B' +select unique2 from onek2 where unique2 = 11 and stringu1 < 'B' -- !query 30 schema -struct +struct -- !query 30 output -0 998 -494 11 +11 -- !query 31 select unique1, unique2 from onek2 - where (unique2 = 11 and stringu1 < 'B') or unique1 = 0 + where (unique2 = 11 or unique1 = 0) and stringu1 < 'B' -- !query 31 schema struct -- !query 31 output @@ -502,24 +500,25 @@ struct -- !query 32 -SELECT 1 AS x ORDER BY x +select unique1, unique2 from onek2 + where (unique2 = 11 and stringu1 < 'B') or unique1 = 0 -- !query 32 schema -struct +struct -- !query 32 output -1 +0 998 +494 11 -- !query 33 -select * from (values (2),(null),(1)) v(k) where k = k order by k +SELECT 1 AS x ORDER BY x -- !query 33 schema -struct +struct -- !query 33 output 1 -2 -- !query 34 -select * from (values (2),(null),(1)) v(k) where k = k +select * from (values (2),(null),(1)) v(k) where k = k order by k -- !query 34 schema struct -- !query 34 output @@ -528,8 +527,17 @@ struct -- !query 35 -drop table tmp +select * from (values (2),(null),(1)) v(k) where k = k -- !query 35 schema -struct<> +struct -- !query 35 output +1 +2 + + +-- !query 36 +drop table tmp +-- !query 36 schema +struct<> +-- !query 36 output diff --git a/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out b/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out index c05a33a5e5ece..8efeae3a1bd09 100644 --- a/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/show-tables.sql.out @@ -67,7 +67,6 @@ aggtest arraydata mapdata onek -onek2 show_t1 show_t2 show_t3 @@ -84,7 +83,6 @@ aggtest arraydata mapdata onek -onek2 show_t1 show_t2 show_t3 diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala index ba183f9d3cc42..c8a187b57a610 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala @@ -487,32 +487,6 @@ class SQLQueryTestSuite extends QueryTest with SharedSQLContext { """.stripMargin) .load(testFile("test-data/postgresql/tenk.data")) .createOrReplaceTempView("tenk1") - - session - .read - .format("csv") - .options(Map("delimiter" -> "\t", "header" -> "false")) - .schema( - """ - |unique1 int, - |unique2 int, - |two int, - |four int, - |ten int, - |twenty int, - |hundred int, - |thousand int, - |twothousand int, - |fivethous int, - |tenthous int, - |odd int, - |even int, - |stringu1 string, - |stringu2 string, - |string4 string - """.stripMargin) - .load(testFile("test-data/postgresql/onek.data")) - .createOrReplaceTempView("onek2") } private val originalTimeZone = TimeZone.getDefault From 092bba95543c861146bafbd6a529913e353a4d51 Mon Sep 17 00:00:00 2001 From: Yuming Wang Date: Thu, 11 Jul 2019 18:34:57 +0800 Subject: [PATCH 6/6] Address comment --- sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql index e4e9ca932f810..1f83d6c41661f 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/pgSQL/select.sql @@ -105,6 +105,9 @@ SELECT onek2.unique1, onek2.stringu1 FROM onek2 -- RESET enable_sort; -- [SPARK-28329] SELECT INTO syntax +-- SELECT two, stringu1, ten, string4 +-- INTO TABLE tmp +-- FROM onek; CREATE TABLE tmp USING parquet AS SELECT two, stringu1, ten, string4 FROM onek;