From 0128b5d07f7d0a1c6e41bdb53e4d047750e0e3ad Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Mon, 14 Oct 2019 21:01:46 -0300 Subject: [PATCH 1/4] adds window_sql part1 Signed-off-by: DylanGuedes --- .../inputs/postgreSQL/window_part1.sql | 348 +++++++ .../results/postgreSQL/window_part1.sql.out | 905 ++++++++++++++++++ 2 files changed, 1253 insertions(+) create mode 100644 sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql create mode 100644 sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out diff --git a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql new file mode 100644 index 0000000000000..2c868d7c38de9 --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql @@ -0,0 +1,348 @@ +-- Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group +-- +-- Window Functions Testing +-- https://github.com/postgres/postgres/blob/REL_12_STABLE/src/test/regress/sql/window.sql#L1-L319 + +CREATE TEMPORARY VIEW tenk2 AS SELECT * FROM tenk1; + +CREATE TABLE empsalary ( + depname string, + empno integer, + salary int, + enroll_date date +) USING parquet; + +INSERT INTO empsalary VALUES +('develop', 10, 5200, '2007-08-01'), +('sales', 1, 5000, '2006-10-01'), +('personnel', 5, 3500, '2007-12-10'), +('sales', 4, 4800, '2007-08-08'), +('personnel', 2, 3900, '2006-12-23'), +('develop', 7, 4200, '2008-01-01'), +('develop', 9, 4500, '2008-01-01'), +('sales', 3, 4800, '2007-08-01'), +('develop', 8, 6000, '2006-10-01'), +('develop', 11, 5200, '2007-08-15'); + +SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary; + +SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary) FROM empsalary; + +-- with GROUP BY +SELECT four, ten, SUM(SUM(four)) OVER (PARTITION BY four), AVG(ten) FROM tenk1 +GROUP BY four, ten ORDER BY four, ten; + +SELECT depname, empno, salary, sum(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname); + +-- [SPARK-28064] Order by does not accept a call to rank() +-- SELECT depname, empno, salary, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary) ORDER BY rank() OVER w; + +-- empty window specification +SELECT COUNT(*) OVER () FROM tenk1 WHERE unique2 < 10; + +SELECT COUNT(*) OVER w FROM tenk1 WHERE unique2 < 10 WINDOW w AS (); + +-- no window operation +SELECT four FROM tenk1 WHERE FALSE WINDOW w AS (PARTITION BY ten); + +-- cumulative aggregate +SELECT sum(four) OVER (PARTITION BY ten ORDER BY unique2) AS sum_1, ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT row_number() OVER (ORDER BY unique2) FROM tenk1 WHERE unique2 < 10; + +SELECT rank() OVER (PARTITION BY four ORDER BY ten) AS rank_1, ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT dense_rank() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT percent_rank() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT cume_dist() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT ntile(3) OVER (ORDER BY ten, four), ten, four FROM tenk1 WHERE unique2 < 10; + +-- [SPARK-28065] ntile does not accept NULL as input +-- SELECT ntile(NULL) OVER (ORDER BY ten, four), ten, four FROM tenk1 LIMIT 2; + +SELECT lag(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +-- [SPARK-28068] `lag` second argument must be a literal in Spark +-- SELECT lag(ten, four) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +-- [SPARK-28068] `lag` second argument must be a literal in Spark +-- SELECT lag(ten, four, 0) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT lead(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT lead(ten * 2, 1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT lead(ten * 2, 1, -1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT first(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +-- last returns the last row of the frame, which is CURRENT ROW in ORDER BY window. +SELECT last(four) OVER (ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10; + +SELECT last(ten) OVER (PARTITION BY four), ten, four FROM +(SELECT * FROM tenk1 WHERE unique2 < 10 ORDER BY four, ten)s +ORDER BY four, ten; + +-- [SPARK-27951] ANSI SQL: NTH_VALUE function +-- SELECT nth_value(ten, four + 1) OVER (PARTITION BY four), ten, four +-- FROM (SELECT * FROM tenk1 WHERE unique2 < 10 ORDER BY four, ten)s; + +SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER (PARTITION BY two ORDER BY ten) AS wsum +FROM tenk1 GROUP BY ten, two; + +SELECT count(*) OVER (PARTITION BY four), four FROM (SELECT * FROM tenk1 WHERE two = 1)s WHERE unique2 < 10; + +SELECT (count(*) OVER (PARTITION BY four ORDER BY ten) + + sum(hundred) OVER (PARTITION BY four ORDER BY ten)) AS cntsum + FROM tenk1 WHERE unique2 < 10; + +-- opexpr with different windows evaluation. +SELECT * FROM( + SELECT count(*) OVER (PARTITION BY four ORDER BY ten) + + sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS total, + count(*) OVER (PARTITION BY four ORDER BY ten) AS fourcount, + sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS twosum + FROM tenk1 +)sub WHERE total <> fourcount + twosum; + +SELECT avg(four) OVER (PARTITION BY four ORDER BY thousand / 100) FROM tenk1 WHERE unique2 < 10; + +SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER win AS wsum +FROM tenk1 GROUP BY ten, two WINDOW win AS (PARTITION BY two ORDER BY ten); + +-- more than one window with GROUP BY +SELECT sum(salary), + row_number() OVER (ORDER BY depname), + sum(sum(salary)) OVER (ORDER BY depname DESC) +FROM empsalary GROUP BY depname; + +-- identical windows with different names +SELECT sum(salary) OVER w1, count(*) OVER w2 +FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary); + +-- subplan +-- [SPARK-28379] Correlated scalar subqueries must be aggregated +-- SELECT lead(ten, (SELECT two FROM tenk1 WHERE s.unique2 = unique2)) OVER (PARTITION BY four ORDER BY ten) +-- FROM tenk1 s WHERE unique2 < 10; + +-- empty table +SELECT count(*) OVER (PARTITION BY four) FROM (SELECT * FROM tenk1 WHERE FALSE)s; + +-- mixture of agg/wfunc in the same window +SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC); + +-- strict aggs +-- Temporarily turns off the ANSI mode because of compatibility issues between +-- keywords related to date (in this case, year) +SET spark.sql.parser.ansi.enabled=false; +SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( +SELECT *, + CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, + CASE WHEN + AVG(salary) OVER (PARTITION BY depname) < salary + THEN 200 END AS depadj FROM empsalary + )s; +SET spark.sql.parser.ansi.enabled=true; + +create temporary view int4_tbl as select * from values + (0), + (123456), + (-123456), + (2147483647), + (-2147483647) + as int4_tbl(f1); + +-- window function over ungrouped agg over empty row set (bug before 9.1) +SELECT SUM(COUNT(f1)) OVER () FROM int4_tbl WHERE f1=42; + +-- window function with ORDER BY an expression involving aggregates (9.1 bug) +select ten, + sum(unique1) + sum(unique2) as res, + rank() over (order by sum(unique1) + sum(unique2)) as rank +from tenk1 +group by ten order by ten; + +-- window and aggregate with GROUP BY expression (9.2 bug) +-- explain +-- select first(max(x)) over (), y +-- from (select unique1 as x, ten+four as y from tenk1) ss +-- group by y; + +-- test non-default frame specifications +SELECT four, ten, +sum(ten) over (partition by four order by ten), +last(ten) over (partition by four order by ten) +FROM (select distinct ten, four from tenk1) ss; + +SELECT four, ten, +sum(ten) over (partition by four order by ten range between unbounded preceding and current row), +last(ten) over (partition by four order by ten range between unbounded preceding and current row) +FROM (select distinct ten, four from tenk1) ss; + +SELECT four, ten, +sum(ten) over (partition by four order by ten range between unbounded preceding and unbounded following), +last(ten) over (partition by four order by ten range between unbounded preceding and unbounded following) +FROM (select distinct ten, four from tenk1) ss; + +-- [SPARK-29451] Some queries with divisions in SQL windows are failling in Thrift +-- SELECT four, ten/4 as two, +-- sum(ten/4) over (partition by four order by ten/4 range between unbounded preceding and current row), +-- last(ten/4) over (partition by four order by ten/4 range between unbounded preceding and current row) +-- FROM (select distinct ten, four from tenk1) ss; + +-- [SPARK-29451] Some queries with divisions in SQL windows are failling in Thrift +-- SELECT four, ten/4 as two, +-- sum(ten/4) over (partition by four order by ten/4 rows between unbounded preceding and current row), +-- last(ten/4) over (partition by four order by ten/4 rows between unbounded preceding and current row) +-- FROM (select distinct ten, four from tenk1) ss; + +SELECT sum(unique1) over (order by four range between current row and unbounded following), +unique1, four +FROM tenk1 WHERE unique1 < 10; + +SELECT sum(unique1) over (rows between current row and unbounded following), +unique1, four +FROM tenk1 WHERE unique1 < 10; + +SELECT sum(unique1) over (rows between 2 preceding and 2 following), +unique1, four +FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (rows between 2 preceding and 2 following exclude no others), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (rows between 2 preceding and 2 following exclude current row), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (rows between 2 preceding and 2 following exclude group), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (rows between 2 preceding and 2 following exclude ties), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT first(unique1) over (ORDER BY four rows between current row and 2 following exclude current row), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT first(unique1) over (ORDER BY four rows between current row and 2 following exclude group), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT first(unique1) over (ORDER BY four rows between current row and 2 following exclude ties), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT last(unique1) over (ORDER BY four rows between current row and 2 following exclude current row), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT last(unique1) over (ORDER BY four rows between current row and 2 following exclude group), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT last(unique1) over (ORDER BY four rows between current row and 2 following exclude ties), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10; + +SELECT sum(unique1) over (rows between 2 preceding and 1 preceding), +unique1, four +FROM tenk1 WHERE unique1 < 10; + +SELECT sum(unique1) over (rows between 1 following and 3 following), +unique1, four +FROM tenk1 WHERE unique1 < 10; + +SELECT sum(unique1) over (rows between unbounded preceding and 1 following), +unique1, four +FROM tenk1 WHERE unique1 < 10; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (w range between current row and unbounded following), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10 WINDOW w AS (order by four); + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (w range between unbounded preceding and current row exclude current row), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10 WINDOW w AS (order by four); + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (w range between unbounded preceding and current row exclude group), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10 WINDOW w AS (order by four); + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- SELECT sum(unique1) over (w range between unbounded preceding and current row exclude ties), +-- unique1, four +-- FROM tenk1 WHERE unique1 < 10 WINDOW w AS (order by four); + +-- [SPARK-27951] ANSI SQL: NTH_VALUE function +-- SELECT first_value(unique1) over w, +-- nth_value(unique1, 2) over w AS nth_2, +-- last_value(unique1) over w, unique1, four +-- FROM tenk1 WHERE unique1 < 10 +-- WINDOW w AS (order by four range between current row and unbounded following); + +-- [SPARK-28501] Frame bound value must be a literal. +-- SELECT sum(unique1) over +-- (order by unique1 +-- rows (SELECT unique1 FROM tenk1 ORDER BY unique1 LIMIT 1) + 1 PRECEDING), +-- unique1 +-- FROM tenk1 WHERE unique1 < 10; + +CREATE TEMP VIEW v_window AS +SELECT i.id, sum(i.id) over (order by i.id rows between 1 preceding and 1 following) as sum_rows +FROM range(1, 11) i; + +SELECT * FROM v_window; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- CREATE OR REPLACE TEMP VIEW v_window AS +-- SELECT i, sum(i) over (order by i rows between 1 preceding and 1 following +-- exclude current row) as sum_rows FROM range(1, 10) i; + +-- SELECT * FROM v_window; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- CREATE OR REPLACE TEMP VIEW v_window AS +-- SELECT i, sum(i) over (order by i rows between 1 preceding and 1 following +-- exclude group) as sum_rows FROM range(1, 10) i; +-- SELECT * FROM v_window; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- CREATE OR REPLACE TEMP VIEW v_window AS +-- SELECT i, sum(i) over (order by i rows between 1 preceding and 1 following +-- exclude ties) as sum_rows FROM generate_series(1, 10) i; + +-- [SPARK-28428] Spark `exclude` always expecting `()` +-- CREATE OR REPLACE TEMP VIEW v_window AS +-- SELECT i, sum(i) over (order by i rows between 1 preceding and 1 following +-- exclude no others) as sum_rows FROM generate_series(1, 10) i; +-- SELECT * FROM v_window; + +-- [SPARK-28648] Adds support to `groups` unit type in window clauses +-- CREATE OR REPLACE TEMP VIEW v_window AS +-- SELECT i.id, sum(i.id) over (order by i.id groups between 1 preceding and 1 following) as sum_rows FROM range(1, 11) i; +-- SELECT * FROM v_window; + +DROP VIEW v_window; +DROP TABLE empsalary; +DROP VIEW tenk2; +DROP VIEW int4_tbl; diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out new file mode 100644 index 0000000000000..db9cf4c7c2f1f --- /dev/null +++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out @@ -0,0 +1,905 @@ +-- Automatically generated by SQLQueryTestSuite +-- Number of queries: 55 + + +-- !query 0 +CREATE TEMPORARY VIEW tenk2 AS SELECT * FROM tenk1 +-- !query 0 schema +struct<> +-- !query 0 output + + + +-- !query 1 +CREATE TABLE empsalary ( + depname string, + empno integer, + salary int, + enroll_date date +) USING parquet +-- !query 1 schema +struct<> +-- !query 1 output + + + +-- !query 2 +INSERT INTO empsalary VALUES +('develop', 10, 5200, '2007-08-01'), +('sales', 1, 5000, '2006-10-01'), +('personnel', 5, 3500, '2007-12-10'), +('sales', 4, 4800, '2007-08-08'), +('personnel', 2, 3900, '2006-12-23'), +('develop', 7, 4200, '2008-01-01'), +('develop', 9, 4500, '2008-01-01'), +('sales', 3, 4800, '2007-08-01'), +('develop', 8, 6000, '2006-10-01'), +('develop', 11, 5200, '2007-08-15') +-- !query 2 schema +struct<> +-- !query 2 output + + + +-- !query 3 +SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary +-- !query 3 schema +struct +-- !query 3 output +develop 7 4200 25100 +develop 9 4500 25100 +develop 10 5200 25100 +develop 11 5200 25100 +develop 8 6000 25100 +personnel 5 3500 7400 +personnel 2 3900 7400 +sales 4 4800 14600 +sales 3 4800 14600 +sales 1 5000 14600 + + +-- !query 4 +SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary) FROM empsalary +-- !query 4 schema +struct +-- !query 4 output +develop 10 5200 3 +develop 11 5200 3 +develop 7 4200 1 +develop 8 6000 5 +develop 9 4500 2 +personnel 2 3900 2 +personnel 5 3500 1 +sales 1 5000 3 +sales 3 4800 1 +sales 4 4800 1 + + +-- !query 5 +SELECT four, ten, SUM(SUM(four)) OVER (PARTITION BY four), AVG(ten) FROM tenk1 +GROUP BY four, ten ORDER BY four, ten +-- !query 5 schema +struct +-- !query 5 output +0 0 0 0.0 +0 2 0 2.0 +0 4 0 4.0 +0 6 0 6.0 +0 8 0 8.0 +1 1 2500 1.0 +1 3 2500 3.0 +1 5 2500 5.0 +1 7 2500 7.0 +1 9 2500 9.0 +2 0 5000 0.0 +2 2 5000 2.0 +2 4 5000 4.0 +2 6 5000 6.0 +2 8 5000 8.0 +3 1 7500 1.0 +3 3 7500 3.0 +3 5 7500 5.0 +3 7 7500 7.0 +3 9 7500 9.0 + + +-- !query 6 +SELECT depname, empno, salary, sum(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname) +-- !query 6 schema +struct +-- !query 6 output +develop 10 5200 25100 +develop 11 5200 25100 +develop 7 4200 25100 +develop 8 6000 25100 +develop 9 4500 25100 +personnel 2 3900 7400 +personnel 5 3500 7400 +sales 1 5000 14600 +sales 3 4800 14600 +sales 4 4800 14600 + + +-- !query 7 +SELECT COUNT(*) OVER () FROM tenk1 WHERE unique2 < 10 +-- !query 7 schema +struct +-- !query 7 output +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 + + +-- !query 8 +SELECT COUNT(*) OVER w FROM tenk1 WHERE unique2 < 10 WINDOW w AS () +-- !query 8 schema +struct +-- !query 8 output +10 +10 +10 +10 +10 +10 +10 +10 +10 +10 + + +-- !query 9 +SELECT four FROM tenk1 WHERE FALSE WINDOW w AS (PARTITION BY ten) +-- !query 9 schema +struct +-- !query 9 output + + + +-- !query 10 +SELECT sum(four) OVER (PARTITION BY ten ORDER BY unique2) AS sum_1, ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 10 schema +struct +-- !query 10 output +0 0 0 +0 0 0 +0 4 0 +1 7 1 +1 9 1 +2 0 2 +3 1 3 +3 3 3 +4 1 1 +5 1 1 + + +-- !query 11 +SELECT row_number() OVER (ORDER BY unique2) FROM tenk1 WHERE unique2 < 10 +-- !query 11 schema +struct +-- !query 11 output +1 +10 +2 +3 +4 +5 +6 +7 +8 +9 + + +-- !query 12 +SELECT rank() OVER (PARTITION BY four ORDER BY ten) AS rank_1, ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 12 schema +struct +-- !query 12 output +1 0 0 +1 0 0 +1 0 2 +1 1 1 +1 1 1 +1 1 3 +2 3 3 +3 4 0 +3 7 1 +4 9 1 + + +-- !query 13 +SELECT dense_rank() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 13 schema +struct +-- !query 13 output +1 0 0 +1 0 0 +1 0 2 +1 1 1 +1 1 1 +1 1 3 +2 3 3 +2 4 0 +2 7 1 +3 9 1 + + +-- !query 14 +SELECT percent_rank() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 14 schema +struct +-- !query 14 output +0.0 0 0 +0.0 0 0 +0.0 0 2 +0.0 1 1 +0.0 1 1 +0.0 1 3 +0.6666666666666666 7 1 +1.0 3 3 +1.0 4 0 +1.0 9 1 + + +-- !query 15 +SELECT cume_dist() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 15 schema +struct +-- !query 15 output +0.5 1 1 +0.5 1 1 +0.5 1 3 +0.6666666666666666 0 0 +0.6666666666666666 0 0 +0.75 7 1 +1.0 0 2 +1.0 3 3 +1.0 4 0 +1.0 9 1 + + +-- !query 16 +SELECT ntile(3) OVER (ORDER BY ten, four), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 16 schema +struct +-- !query 16 output +1 0 0 +1 0 0 +1 0 2 +1 1 1 +2 1 1 +2 1 3 +2 3 3 +3 4 0 +3 7 1 +3 9 1 + + +-- !query 17 +SELECT lag(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 17 schema +struct +-- !query 17 output +0 0 0 +0 4 0 +1 1 1 +1 3 3 +1 7 1 +7 9 1 +NULL 0 0 +NULL 0 2 +NULL 1 1 +NULL 1 3 + + +-- !query 18 +SELECT lead(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 18 schema +struct +-- !query 18 output +0 0 0 +1 1 1 +3 1 3 +4 0 0 +7 1 1 +9 7 1 +NULL 0 2 +NULL 3 3 +NULL 4 0 +NULL 9 1 + + +-- !query 19 +SELECT lead(ten * 2, 1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 19 schema +struct +-- !query 19 output +0 0 0 +14 1 1 +18 7 1 +2 1 1 +6 1 3 +8 0 0 +NULL 0 2 +NULL 3 3 +NULL 4 0 +NULL 9 1 + + +-- !query 20 +SELECT lead(ten * 2, 1, -1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 20 schema +struct +-- !query 20 output +-1 0 2 +-1 3 3 +-1 4 0 +-1 9 1 +0 0 0 +14 1 1 +18 7 1 +2 1 1 +6 1 3 +8 0 0 + + +-- !query 21 +SELECT first(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 21 schema +struct +-- !query 21 output +0 0 0 +0 0 0 +0 0 2 +0 4 0 +1 1 1 +1 1 1 +1 1 3 +1 3 3 +1 7 1 +1 9 1 + + +-- !query 22 +SELECT last(four) OVER (ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 +-- !query 22 schema +struct +-- !query 22 output +0 4 0 +1 1 1 +1 1 1 +1 1 3 +1 7 1 +1 9 1 +2 0 0 +2 0 0 +2 0 2 +3 3 3 + + +-- !query 23 +SELECT last(ten) OVER (PARTITION BY four), ten, four FROM +(SELECT * FROM tenk1 WHERE unique2 < 10 ORDER BY four, ten)s +ORDER BY four, ten +-- !query 23 schema +struct +-- !query 23 output +4 0 0 +4 0 0 +4 4 0 +9 1 1 +9 1 1 +9 7 1 +9 9 1 +0 0 2 +3 1 3 +3 3 3 + + +-- !query 24 +SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER (PARTITION BY two ORDER BY ten) AS wsum +FROM tenk1 GROUP BY ten, two +-- !query 24 schema +struct +-- !query 24 output +0 0 45000 45000 +1 1 46000 46000 +2 0 47000 92000 +3 1 48000 94000 +4 0 49000 141000 +5 1 50000 144000 +6 0 51000 192000 +7 1 52000 196000 +8 0 53000 245000 +9 1 54000 250000 + + +-- !query 25 +SELECT count(*) OVER (PARTITION BY four), four FROM (SELECT * FROM tenk1 WHERE two = 1)s WHERE unique2 < 10 +-- !query 25 schema +struct +-- !query 25 output +2 3 +2 3 +4 1 +4 1 +4 1 +4 1 + + +-- !query 26 +SELECT (count(*) OVER (PARTITION BY four ORDER BY ten) + + sum(hundred) OVER (PARTITION BY four ORDER BY ten)) AS cntsum + FROM tenk1 WHERE unique2 < 10 +-- !query 26 schema +struct +-- !query 26 output +136 +22 +22 +24 +24 +51 +82 +87 +92 +92 + + +-- !query 27 +SELECT * FROM( + SELECT count(*) OVER (PARTITION BY four ORDER BY ten) + + sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS total, + count(*) OVER (PARTITION BY four ORDER BY ten) AS fourcount, + sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS twosum + FROM tenk1 +)sub WHERE total <> fourcount + twosum +-- !query 27 schema +struct +-- !query 27 output + + + +-- !query 28 +SELECT avg(four) OVER (PARTITION BY four ORDER BY thousand / 100) FROM tenk1 WHERE unique2 < 10 +-- !query 28 schema +struct +-- !query 28 output +0.0 +0.0 +0.0 +1.0 +1.0 +1.0 +1.0 +2.0 +3.0 +3.0 + + +-- !query 29 +SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER win AS wsum +FROM tenk1 GROUP BY ten, two WINDOW win AS (PARTITION BY two ORDER BY ten) +-- !query 29 schema +struct +-- !query 29 output +0 0 45000 45000 +1 1 46000 46000 +2 0 47000 92000 +3 1 48000 94000 +4 0 49000 141000 +5 1 50000 144000 +6 0 51000 192000 +7 1 52000 196000 +8 0 53000 245000 +9 1 54000 250000 + + +-- !query 30 +SELECT sum(salary), + row_number() OVER (ORDER BY depname), + sum(sum(salary)) OVER (ORDER BY depname DESC) +FROM empsalary GROUP BY depname +-- !query 30 schema +struct +-- !query 30 output +14600 3 14600 +25100 1 47100 +7400 2 22000 + + +-- !query 31 +SELECT sum(salary) OVER w1, count(*) OVER w2 +FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary) +-- !query 31 schema +struct +-- !query 31 output +11600 3 +16100 4 +25700 6 +25700 6 +30700 7 +3500 1 +41100 9 +41100 9 +47100 10 +7400 2 + + +-- !query 32 +SELECT count(*) OVER (PARTITION BY four) FROM (SELECT * FROM tenk1 WHERE FALSE)s +-- !query 32 schema +struct +-- !query 32 output + + + +-- !query 33 +SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC) +-- !query 33 schema +struct +-- !query 33 output +14600 2 +14600 2 +16400 2 +16400 2 +20900 4 +25100 5 +3900 1 +5000 1 +6000 1 +7400 2 + + +-- !query 34 +SET spark.sql.parser.ansi.enabled=false +-- !query 34 schema +struct +-- !query 34 output +spark.sql.parser.ansi.enabled false + + +-- !query 35 +SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( +SELECT *, + CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, + CASE WHEN + AVG(salary) OVER (PARTITION BY depname) < salary + THEN 200 END AS depadj FROM empsalary + )s +-- !query 35 schema +struct<> +-- !query 35 output +org.apache.spark.sql.catalyst.parser.ParseException + +no viable alternative at input 'year'(line 3, pos 59) + +== SQL == +SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( +SELECT *, + CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, +-----------------------------------------------------------^^^ + CASE WHEN + AVG(salary) OVER (PARTITION BY depname) < salary + THEN 200 END AS depadj FROM empsalary + )s + + +-- !query 36 +SET spark.sql.parser.ansi.enabled=true +-- !query 36 schema +struct +-- !query 36 output +spark.sql.parser.ansi.enabled true + + +-- !query 37 +create temporary view int4_tbl as select * from values + (0), + (123456), + (-123456), + (2147483647), + (-2147483647) + as int4_tbl(f1) +-- !query 37 schema +struct<> +-- !query 37 output + + + +-- !query 38 +SELECT SUM(COUNT(f1)) OVER () FROM int4_tbl WHERE f1=42 +-- !query 38 schema +struct +-- !query 38 output +0 + + +-- !query 39 +select ten, + sum(unique1) + sum(unique2) as res, + rank() over (order by sum(unique1) + sum(unique2)) as rank +from tenk1 +group by ten order by ten +-- !query 39 schema +struct +-- !query 39 output +0 9976146 4 +1 10114187 9 +2 10059554 8 +3 9878541 1 +4 9881005 2 +5 9981670 5 +6 9947099 3 +7 10120309 10 +8 9991305 6 +9 10040184 7 + + +-- !query 40 +SELECT four, ten, +sum(ten) over (partition by four order by ten), +last(ten) over (partition by four order by ten) +FROM (select distinct ten, four from tenk1) ss +-- !query 40 schema +struct +-- !query 40 output +0 0 0 0 +0 2 2 2 +0 4 6 4 +0 6 12 6 +0 8 20 8 +1 1 1 1 +1 3 4 3 +1 5 9 5 +1 7 16 7 +1 9 25 9 +2 0 0 0 +2 2 2 2 +2 4 6 4 +2 6 12 6 +2 8 20 8 +3 1 1 1 +3 3 4 3 +3 5 9 5 +3 7 16 7 +3 9 25 9 + + +-- !query 41 +SELECT four, ten, +sum(ten) over (partition by four order by ten range between unbounded preceding and current row), +last(ten) over (partition by four order by ten range between unbounded preceding and current row) +FROM (select distinct ten, four from tenk1) ss +-- !query 41 schema +struct +-- !query 41 output +0 0 0 0 +0 2 2 2 +0 4 6 4 +0 6 12 6 +0 8 20 8 +1 1 1 1 +1 3 4 3 +1 5 9 5 +1 7 16 7 +1 9 25 9 +2 0 0 0 +2 2 2 2 +2 4 6 4 +2 6 12 6 +2 8 20 8 +3 1 1 1 +3 3 4 3 +3 5 9 5 +3 7 16 7 +3 9 25 9 + + +-- !query 42 +SELECT four, ten, +sum(ten) over (partition by four order by ten range between unbounded preceding and unbounded following), +last(ten) over (partition by four order by ten range between unbounded preceding and unbounded following) +FROM (select distinct ten, four from tenk1) ss +-- !query 42 schema +struct +-- !query 42 output +0 0 20 8 +0 2 20 8 +0 4 20 8 +0 6 20 8 +0 8 20 8 +1 1 25 9 +1 3 25 9 +1 5 25 9 +1 7 25 9 +1 9 25 9 +2 0 20 8 +2 2 20 8 +2 4 20 8 +2 6 20 8 +2 8 20 8 +3 1 25 9 +3 3 25 9 +3 5 25 9 +3 7 25 9 +3 9 25 9 + + +-- !query 43 +SELECT sum(unique1) over (order by four range between current row and unbounded following), +unique1, four +FROM tenk1 WHERE unique1 < 10 +-- !query 43 schema +struct +-- !query 43 output +10 3 3 +10 7 3 +18 2 2 +18 6 2 +33 1 1 +33 5 1 +33 9 1 +45 0 0 +45 4 0 +45 8 0 + + +-- !query 44 +SELECT sum(unique1) over (rows between current row and unbounded following), +unique1, four +FROM tenk1 WHERE unique1 < 10 +-- !query 44 schema +struct +-- !query 44 output +0 0 0 +10 3 3 +15 5 1 +23 8 0 +32 9 1 +38 6 2 +39 1 1 +41 2 2 +45 4 0 +7 7 3 + + +-- !query 45 +SELECT sum(unique1) over (rows between 2 preceding and 2 following), +unique1, four +FROM tenk1 WHERE unique1 < 10 +-- !query 45 schema +struct +-- !query 45 output +10 0 0 +13 2 2 +15 7 3 +22 1 1 +23 3 3 +26 6 2 +29 9 1 +31 8 0 +32 5 1 +7 4 0 + + +-- !query 46 +SELECT sum(unique1) over (rows between 2 preceding and 1 preceding), +unique1, four +FROM tenk1 WHERE unique1 < 10 +-- !query 46 schema +struct +-- !query 46 output +10 0 0 +13 3 3 +15 8 0 +17 5 1 +3 6 2 +4 2 2 +6 1 1 +7 9 1 +8 7 3 +NULL 4 0 + + +-- !query 47 +SELECT sum(unique1) over (rows between 1 following and 3 following), +unique1, four +FROM tenk1 WHERE unique1 < 10 +-- !query 47 schema +struct +-- !query 47 output +0 7 3 +10 5 1 +15 8 0 +16 2 2 +16 9 1 +22 6 2 +23 1 1 +7 3 3 +9 4 0 +NULL 0 0 + + +-- !query 48 +SELECT sum(unique1) over (rows between unbounded preceding and 1 following), +unique1, four +FROM tenk1 WHERE unique1 < 10 +-- !query 48 schema +struct +-- !query 48 output +13 1 1 +22 6 2 +30 9 1 +35 8 0 +38 5 1 +45 0 0 +45 3 3 +45 7 3 +6 4 0 +7 2 2 + + +-- !query 49 +CREATE TEMP VIEW v_window AS +SELECT i.id, sum(i.id) over (order by i.id rows between 1 preceding and 1 following) as sum_rows +FROM range(1, 11) i +-- !query 49 schema +struct<> +-- !query 49 output + + + +-- !query 50 +SELECT * FROM v_window +-- !query 50 schema +struct +-- !query 50 output +1 3 +10 19 +2 6 +3 9 +4 12 +5 15 +6 18 +7 21 +8 24 +9 27 + + +-- !query 51 +DROP VIEW v_window +-- !query 51 schema +struct<> +-- !query 51 output + + + +-- !query 52 +DROP TABLE empsalary +-- !query 52 schema +struct<> +-- !query 52 output + + + +-- !query 53 +DROP VIEW tenk2 +-- !query 53 schema +struct<> +-- !query 53 output + + + +-- !query 54 +DROP VIEW int4_tbl +-- !query 54 schema +struct<> +-- !query 54 output + From 2c8d3efc5ac832df9006fb02b777ff8369984724 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Tue, 15 Oct 2019 21:29:00 -0300 Subject: [PATCH 2/4] remove broken query Signed-off-by: DylanGuedes --- .../inputs/postgreSQL/window_part1.sql | 20 +-- .../results/postgreSQL/window_part1.sql.out | 150 +++++++----------- 2 files changed, 62 insertions(+), 108 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql index 2c868d7c38de9..3dccb394f0e23 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql @@ -134,18 +134,14 @@ SELECT count(*) OVER (PARTITION BY four) FROM (SELECT * FROM tenk1 WHERE FALSE)s -- mixture of agg/wfunc in the same window SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC); --- strict aggs --- Temporarily turns off the ANSI mode because of compatibility issues between --- keywords related to date (in this case, year) -SET spark.sql.parser.ansi.enabled=false; -SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( -SELECT *, - CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, - CASE WHEN - AVG(salary) OVER (PARTITION BY depname) < salary - THEN 200 END AS depadj FROM empsalary - )s; -SET spark.sql.parser.ansi.enabled=true; +-- Cannot safely cast 'enroll_date': StringType to DateType; +-- SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( +-- SELECT *, +-- CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, +-- CASE WHEN +-- AVG(salary) OVER (PARTITION BY depname) < salary +-- THEN 200 END AS depadj FROM empsalary +-- )s; create temporary view int4_tbl as select * from values (0), diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out index db9cf4c7c2f1f..6d25866f1265a 100644 --- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 55 +-- Number of queries: 52 -- !query 0 @@ -558,48 +558,6 @@ struct --- !query 34 output -spark.sql.parser.ansi.enabled false - - --- !query 35 -SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( -SELECT *, - CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, - CASE WHEN - AVG(salary) OVER (PARTITION BY depname) < salary - THEN 200 END AS depadj FROM empsalary - )s --- !query 35 schema -struct<> --- !query 35 output -org.apache.spark.sql.catalyst.parser.ParseException - -no viable alternative at input 'year'(line 3, pos 59) - -== SQL == -SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( -SELECT *, - CASE WHEN enroll_date < '2008-01-01' THEN 2008 - extract(year FROM enroll_date) END * 500 AS bonus, ------------------------------------------------------------^^^ - CASE WHEN - AVG(salary) OVER (PARTITION BY depname) < salary - THEN 200 END AS depadj FROM empsalary - )s - - --- !query 36 -SET spark.sql.parser.ansi.enabled=true --- !query 36 schema -struct --- !query 36 output -spark.sql.parser.ansi.enabled true - - --- !query 37 create temporary view int4_tbl as select * from values (0), (123456), @@ -607,29 +565,29 @@ create temporary view int4_tbl as select * from values (2147483647), (-2147483647) as int4_tbl(f1) --- !query 37 schema +-- !query 34 schema struct<> --- !query 37 output +-- !query 34 output --- !query 38 +-- !query 35 SELECT SUM(COUNT(f1)) OVER () FROM int4_tbl WHERE f1=42 --- !query 38 schema +-- !query 35 schema struct --- !query 38 output +-- !query 35 output 0 --- !query 39 +-- !query 36 select ten, sum(unique1) + sum(unique2) as res, rank() over (order by sum(unique1) + sum(unique2)) as rank from tenk1 group by ten order by ten --- !query 39 schema +-- !query 36 schema struct --- !query 39 output +-- !query 36 output 0 9976146 4 1 10114187 9 2 10059554 8 @@ -642,14 +600,14 @@ struct 9 10040184 7 --- !query 40 +-- !query 37 SELECT four, ten, sum(ten) over (partition by four order by ten), last(ten) over (partition by four order by ten) FROM (select distinct ten, four from tenk1) ss --- !query 40 schema +-- !query 37 schema struct --- !query 40 output +-- !query 37 output 0 0 0 0 0 2 2 2 0 4 6 4 @@ -672,14 +630,14 @@ struct --- !query 41 output +-- !query 38 output 0 0 0 0 0 2 2 2 0 4 6 4 @@ -702,14 +660,14 @@ struct --- !query 42 output +-- !query 39 output 0 0 20 8 0 2 20 8 0 4 20 8 @@ -732,13 +690,13 @@ struct --- !query 43 output +-- !query 40 output 10 3 3 10 7 3 18 2 2 @@ -751,13 +709,13 @@ struct --- !query 44 output +-- !query 41 output 0 0 0 10 3 3 15 5 1 @@ -770,13 +728,13 @@ struct --- !query 45 output +-- !query 42 output 10 0 0 13 2 2 15 7 3 @@ -789,13 +747,13 @@ struct --- !query 46 output +-- !query 43 output 10 0 0 13 3 3 15 8 0 @@ -808,13 +766,13 @@ struct --- !query 47 output +-- !query 44 output 0 7 3 10 5 1 15 8 0 @@ -827,13 +785,13 @@ struct --- !query 48 output +-- !query 45 output 13 1 1 22 6 2 30 9 1 @@ -846,21 +804,21 @@ struct --- !query 49 output +-- !query 46 output --- !query 50 +-- !query 47 SELECT * FROM v_window --- !query 50 schema +-- !query 47 schema struct --- !query 50 output +-- !query 47 output 1 3 10 19 2 6 @@ -873,33 +831,33 @@ struct 9 27 --- !query 51 +-- !query 48 DROP VIEW v_window --- !query 51 schema +-- !query 48 schema struct<> --- !query 51 output +-- !query 48 output --- !query 52 +-- !query 49 DROP TABLE empsalary --- !query 52 schema +-- !query 49 schema struct<> --- !query 52 output +-- !query 49 output --- !query 53 +-- !query 50 DROP VIEW tenk2 --- !query 53 schema +-- !query 50 schema struct<> --- !query 53 output +-- !query 50 output --- !query 54 +-- !query 51 DROP VIEW int4_tbl --- !query 54 schema +-- !query 51 schema struct<> --- !query 54 output +-- !query 51 output From 6cd07c8a45f53f8aeb44915cce72aa623cff5501 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Mon, 21 Oct 2019 21:44:10 -0300 Subject: [PATCH 3/4] change how to insert values Signed-off-by: DylanGuedes --- .../inputs/postgreSQL/window_part1.sql | 21 +- .../results/postgreSQL/window_part1.sql.out | 380 ++++++++++-------- 2 files changed, 231 insertions(+), 170 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql index 3dccb394f0e23..75d159f1242d9 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql @@ -12,17 +12,16 @@ CREATE TABLE empsalary ( enroll_date date ) USING parquet; -INSERT INTO empsalary VALUES -('develop', 10, 5200, '2007-08-01'), -('sales', 1, 5000, '2006-10-01'), -('personnel', 5, 3500, '2007-12-10'), -('sales', 4, 4800, '2007-08-08'), -('personnel', 2, 3900, '2006-12-23'), -('develop', 7, 4200, '2008-01-01'), -('develop', 9, 4500, '2008-01-01'), -('sales', 3, 4800, '2007-08-01'), -('develop', 8, 6000, '2006-10-01'), -('develop', 11, 5200, '2007-08-15'); +INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01'); +INSERT INTO empsalary VALUES ('sales', 1, 5000, '2006-10-01'); +INSERT INTO empsalary VALUES ('personnel', 5, 3500, '2007-12-10'); +INSERT INTO empsalary VALUES ('sales', 4, 4800, '2007-08-08'); +INSERT INTO empsalary VALUES ('personnel', 2, 3900, '2006-12-23'); +INSERT INTO empsalary VALUES ('develop', 7, 4200, '2008-01-01'); +INSERT INTO empsalary VALUES ('develop', 9, 4500, '2008-01-01'); +INSERT INTO empsalary VALUES ('sales', 3, 4800, '2007-08-01'); +INSERT INTO empsalary VALUES ('develop', 8, 6000, '2006-10-01'); +INSERT INTO empsalary VALUES ('develop', 11, 5200, '2007-08-15'); SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary; diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out index 6d25866f1265a..fb0f2c2501a9e 100644 --- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 52 +-- Number of queries: 61 -- !query 0 @@ -24,17 +24,7 @@ struct<> -- !query 2 -INSERT INTO empsalary VALUES -('develop', 10, 5200, '2007-08-01'), -('sales', 1, 5000, '2006-10-01'), -('personnel', 5, 3500, '2007-12-10'), -('sales', 4, 4800, '2007-08-08'), -('personnel', 2, 3900, '2006-12-23'), -('develop', 7, 4200, '2008-01-01'), -('develop', 9, 4500, '2008-01-01'), -('sales', 3, 4800, '2007-08-01'), -('develop', 8, 6000, '2006-10-01'), -('develop', 11, 5200, '2007-08-15') +INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01') -- !query 2 schema struct<> -- !query 2 output @@ -42,10 +32,82 @@ struct<> -- !query 3 -SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary +INSERT INTO empsalary VALUES ('sales', 1, 5000, '2006-10-01') -- !query 3 schema -struct +struct<> -- !query 3 output + + + +-- !query 4 +INSERT INTO empsalary VALUES ('personnel', 5, 3500, '2007-12-10') +-- !query 4 schema +struct<> +-- !query 4 output + + + +-- !query 5 +INSERT INTO empsalary VALUES ('sales', 4, 4800, '2007-08-08') +-- !query 5 schema +struct<> +-- !query 5 output + + + +-- !query 6 +INSERT INTO empsalary VALUES ('personnel', 2, 3900, '2006-12-23') +-- !query 6 schema +struct<> +-- !query 6 output + + + +-- !query 7 +INSERT INTO empsalary VALUES ('develop', 7, 4200, '2008-01-01') +-- !query 7 schema +struct<> +-- !query 7 output + + + +-- !query 8 +INSERT INTO empsalary VALUES ('develop', 9, 4500, '2008-01-01') +-- !query 8 schema +struct<> +-- !query 8 output + + + +-- !query 9 +INSERT INTO empsalary VALUES ('sales', 3, 4800, '2007-08-01') +-- !query 9 schema +struct<> +-- !query 9 output + + + +-- !query 10 +INSERT INTO empsalary VALUES ('develop', 8, 6000, '2006-10-01') +-- !query 10 schema +struct<> +-- !query 10 output + + + +-- !query 11 +INSERT INTO empsalary VALUES ('develop', 11, 5200, '2007-08-15') +-- !query 11 schema +struct<> +-- !query 11 output + + + +-- !query 12 +SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary +-- !query 12 schema +struct +-- !query 12 output develop 7 4200 25100 develop 9 4500 25100 develop 10 5200 25100 @@ -53,16 +115,16 @@ develop 11 5200 25100 develop 8 6000 25100 personnel 5 3500 7400 personnel 2 3900 7400 -sales 4 4800 14600 sales 3 4800 14600 +sales 4 4800 14600 sales 1 5000 14600 --- !query 4 +-- !query 13 SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary) FROM empsalary --- !query 4 schema +-- !query 13 schema struct --- !query 4 output +-- !query 13 output develop 10 5200 3 develop 11 5200 3 develop 7 4200 1 @@ -75,12 +137,12 @@ sales 3 4800 1 sales 4 4800 1 --- !query 5 +-- !query 14 SELECT four, ten, SUM(SUM(four)) OVER (PARTITION BY four), AVG(ten) FROM tenk1 GROUP BY four, ten ORDER BY four, ten --- !query 5 schema +-- !query 14 schema struct --- !query 5 output +-- !query 14 output 0 0 0 0.0 0 2 0 2.0 0 4 0 4.0 @@ -103,11 +165,11 @@ struct --- !query 6 output +-- !query 15 output develop 10 5200 25100 develop 11 5200 25100 develop 7 4200 25100 @@ -120,11 +182,11 @@ sales 3 4800 14600 sales 4 4800 14600 --- !query 7 +-- !query 16 SELECT COUNT(*) OVER () FROM tenk1 WHERE unique2 < 10 --- !query 7 schema +-- !query 16 schema struct --- !query 7 output +-- !query 16 output 10 10 10 @@ -137,11 +199,11 @@ struct --- !query 8 output +-- !query 17 output 10 10 10 @@ -154,19 +216,19 @@ struct --- !query 9 output +-- !query 18 output --- !query 10 +-- !query 19 SELECT sum(four) OVER (PARTITION BY ten ORDER BY unique2) AS sum_1, ten, four FROM tenk1 WHERE unique2 < 10 --- !query 10 schema +-- !query 19 schema struct --- !query 10 output +-- !query 19 output 0 0 0 0 0 0 0 4 0 @@ -179,11 +241,11 @@ struct 5 1 1 --- !query 11 +-- !query 20 SELECT row_number() OVER (ORDER BY unique2) FROM tenk1 WHERE unique2 < 10 --- !query 11 schema +-- !query 20 schema struct --- !query 11 output +-- !query 20 output 1 10 2 @@ -196,11 +258,11 @@ struct --- !query 12 output +-- !query 21 output 1 0 0 1 0 0 1 0 2 @@ -213,11 +275,11 @@ struct 4 9 1 --- !query 13 +-- !query 22 SELECT dense_rank() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 13 schema +-- !query 22 schema struct --- !query 13 output +-- !query 22 output 1 0 0 1 0 0 1 0 2 @@ -230,11 +292,11 @@ struct --- !query 14 output +-- !query 23 output 0.0 0 0 0.0 0 0 0.0 0 2 @@ -247,11 +309,11 @@ struct --- !query 15 output +-- !query 24 output 0.5 1 1 0.5 1 1 0.5 1 3 @@ -264,11 +326,11 @@ struct --- !query 16 output +-- !query 25 output 1 0 0 1 0 0 1 0 2 @@ -281,11 +343,11 @@ struct --- !query 17 output +-- !query 26 output 0 0 0 0 4 0 1 1 1 @@ -298,11 +360,11 @@ NULL 1 1 NULL 1 3 --- !query 18 +-- !query 27 SELECT lead(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 18 schema +-- !query 27 schema struct --- !query 18 output +-- !query 27 output 0 0 0 1 1 1 3 1 3 @@ -315,11 +377,11 @@ NULL 4 0 NULL 9 1 --- !query 19 +-- !query 28 SELECT lead(ten * 2, 1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 19 schema +-- !query 28 schema struct --- !query 19 output +-- !query 28 output 0 0 0 14 1 1 18 7 1 @@ -332,11 +394,11 @@ NULL 4 0 NULL 9 1 --- !query 20 +-- !query 29 SELECT lead(ten * 2, 1, -1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 20 schema +-- !query 29 schema struct --- !query 20 output +-- !query 29 output -1 0 2 -1 3 3 -1 4 0 @@ -349,11 +411,11 @@ struct --- !query 21 output +-- !query 30 output 0 0 0 0 0 0 0 0 2 @@ -366,11 +428,11 @@ struct --- !query 22 output +-- !query 31 output 0 4 0 1 1 1 1 1 1 @@ -383,13 +445,13 @@ struct --- !query 23 output +-- !query 32 output 4 0 0 4 0 0 4 4 0 @@ -402,12 +464,12 @@ struct --- !query 24 output +-- !query 33 output 0 0 45000 45000 1 1 46000 46000 2 0 47000 92000 @@ -420,11 +482,11 @@ struct 9 1 54000 250000 --- !query 25 +-- !query 34 SELECT count(*) OVER (PARTITION BY four), four FROM (SELECT * FROM tenk1 WHERE two = 1)s WHERE unique2 < 10 --- !query 25 schema +-- !query 34 schema struct --- !query 25 output +-- !query 34 output 2 3 2 3 4 1 @@ -433,13 +495,13 @@ struct --- !query 26 output +-- !query 35 output 136 22 22 @@ -452,7 +514,7 @@ struct 92 --- !query 27 +-- !query 36 SELECT * FROM( SELECT count(*) OVER (PARTITION BY four ORDER BY ten) + sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS total, @@ -460,17 +522,17 @@ SELECT * FROM( sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS twosum FROM tenk1 )sub WHERE total <> fourcount + twosum --- !query 27 schema +-- !query 36 schema struct --- !query 27 output +-- !query 36 output --- !query 28 +-- !query 37 SELECT avg(four) OVER (PARTITION BY four ORDER BY thousand / 100) FROM tenk1 WHERE unique2 < 10 --- !query 28 schema +-- !query 37 schema struct --- !query 28 output +-- !query 37 output 0.0 0.0 0.0 @@ -483,12 +545,12 @@ struct --- !query 29 output +-- !query 38 output 0 0 45000 45000 1 1 46000 46000 2 0 47000 92000 @@ -501,25 +563,25 @@ struct 9 1 54000 250000 --- !query 30 +-- !query 39 SELECT sum(salary), row_number() OVER (ORDER BY depname), sum(sum(salary)) OVER (ORDER BY depname DESC) FROM empsalary GROUP BY depname --- !query 30 schema +-- !query 39 schema struct --- !query 30 output +-- !query 39 output 14600 3 14600 25100 1 47100 7400 2 22000 --- !query 31 +-- !query 40 SELECT sum(salary) OVER w1, count(*) OVER w2 FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary) --- !query 31 schema +-- !query 40 schema struct --- !query 31 output +-- !query 40 output 11600 3 16100 4 25700 6 @@ -532,19 +594,19 @@ struct --- !query 32 output +-- !query 41 output --- !query 33 +-- !query 42 SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC) --- !query 33 schema +-- !query 42 schema struct --- !query 33 output +-- !query 42 output 14600 2 14600 2 16400 2 @@ -557,7 +619,7 @@ struct --- !query 34 output +-- !query 43 output --- !query 35 +-- !query 44 SELECT SUM(COUNT(f1)) OVER () FROM int4_tbl WHERE f1=42 --- !query 35 schema +-- !query 44 schema struct --- !query 35 output +-- !query 44 output 0 --- !query 36 +-- !query 45 select ten, sum(unique1) + sum(unique2) as res, rank() over (order by sum(unique1) + sum(unique2)) as rank from tenk1 group by ten order by ten --- !query 36 schema +-- !query 45 schema struct --- !query 36 output +-- !query 45 output 0 9976146 4 1 10114187 9 2 10059554 8 @@ -600,14 +662,14 @@ struct 9 10040184 7 --- !query 37 +-- !query 46 SELECT four, ten, sum(ten) over (partition by four order by ten), last(ten) over (partition by four order by ten) FROM (select distinct ten, four from tenk1) ss --- !query 37 schema +-- !query 46 schema struct --- !query 37 output +-- !query 46 output 0 0 0 0 0 2 2 2 0 4 6 4 @@ -630,14 +692,14 @@ struct --- !query 38 output +-- !query 47 output 0 0 0 0 0 2 2 2 0 4 6 4 @@ -660,14 +722,14 @@ struct --- !query 39 output +-- !query 48 output 0 0 20 8 0 2 20 8 0 4 20 8 @@ -690,13 +752,13 @@ struct --- !query 40 output +-- !query 49 output 10 3 3 10 7 3 18 2 2 @@ -709,13 +771,13 @@ struct --- !query 41 output +-- !query 50 output 0 0 0 10 3 3 15 5 1 @@ -728,13 +790,13 @@ struct --- !query 42 output +-- !query 51 output 10 0 0 13 2 2 15 7 3 @@ -747,13 +809,13 @@ struct --- !query 43 output +-- !query 52 output 10 0 0 13 3 3 15 8 0 @@ -766,13 +828,13 @@ struct --- !query 44 output +-- !query 53 output 0 7 3 10 5 1 15 8 0 @@ -785,13 +847,13 @@ struct --- !query 45 output +-- !query 54 output 13 1 1 22 6 2 30 9 1 @@ -804,21 +866,21 @@ struct --- !query 46 output +-- !query 55 output --- !query 47 +-- !query 56 SELECT * FROM v_window --- !query 47 schema +-- !query 56 schema struct --- !query 47 output +-- !query 56 output 1 3 10 19 2 6 @@ -831,33 +893,33 @@ struct 9 27 --- !query 48 +-- !query 57 DROP VIEW v_window --- !query 48 schema +-- !query 57 schema struct<> --- !query 48 output +-- !query 57 output --- !query 49 +-- !query 58 DROP TABLE empsalary --- !query 49 schema +-- !query 58 schema struct<> --- !query 49 output +-- !query 58 output --- !query 50 +-- !query 59 DROP VIEW tenk2 --- !query 50 schema +-- !query 59 schema struct<> --- !query 50 output +-- !query 59 output --- !query 51 +-- !query 60 DROP VIEW int4_tbl --- !query 51 schema +-- !query 60 schema struct<> --- !query 51 output +-- !query 60 output From 2448dfcc3117c563e87e10b797d00c8873c1b2b2 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Mon, 21 Oct 2019 22:47:09 -0300 Subject: [PATCH 4/4] adds new jira Signed-off-by: DylanGuedes --- .../inputs/postgreSQL/window_part1.sql | 69 +-- .../results/postgreSQL/window_part1.sql.out | 452 +++++------------- 2 files changed, 165 insertions(+), 356 deletions(-) diff --git a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql index 75d159f1242d9..ae2a015ada245 100644 --- a/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql +++ b/sql/core/src/test/resources/sql-tests/inputs/postgreSQL/window_part1.sql @@ -5,33 +5,38 @@ CREATE TEMPORARY VIEW tenk2 AS SELECT * FROM tenk1; -CREATE TABLE empsalary ( - depname string, - empno integer, - salary int, - enroll_date date -) USING parquet; - -INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01'); -INSERT INTO empsalary VALUES ('sales', 1, 5000, '2006-10-01'); -INSERT INTO empsalary VALUES ('personnel', 5, 3500, '2007-12-10'); -INSERT INTO empsalary VALUES ('sales', 4, 4800, '2007-08-08'); -INSERT INTO empsalary VALUES ('personnel', 2, 3900, '2006-12-23'); -INSERT INTO empsalary VALUES ('develop', 7, 4200, '2008-01-01'); -INSERT INTO empsalary VALUES ('develop', 9, 4500, '2008-01-01'); -INSERT INTO empsalary VALUES ('sales', 3, 4800, '2007-08-01'); -INSERT INTO empsalary VALUES ('develop', 8, 6000, '2006-10-01'); -INSERT INTO empsalary VALUES ('develop', 11, 5200, '2007-08-15'); - -SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary; - -SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary) FROM empsalary; +-- [SPARK-29540] Thrift in some cases can't parse string to date +-- CREATE TABLE empsalary ( +-- depname string, +-- empno integer, +-- salary int, +-- enroll_date date +-- ) USING parquet; + +-- [SPARK-29540] Thrift in some cases can't parse string to date +-- INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01'); +-- INSERT INTO empsalary VALUES ('sales', 1, 5000, '2006-10-01'); +-- INSERT INTO empsalary VALUES ('personnel', 5, 3500, '2007-12-10'); +-- INSERT INTO empsalary VALUES ('sales', 4, 4800, '2007-08-08'); +-- INSERT INTO empsalary VALUES ('personnel', 2, 3900, '2006-12-23'); +-- INSERT INTO empsalary VALUES ('develop', 7, 4200, '2008-01-01'); +-- INSERT INTO empsalary VALUES ('develop', 9, 4500, '2008-01-01'); +-- INSERT INTO empsalary VALUES ('sales', 3, 4800, '2007-08-01'); +-- INSERT INTO empsalary VALUES ('develop', 8, 6000, '2006-10-01'); +-- INSERT INTO empsalary VALUES ('develop', 11, 5200, '2007-08-15'); + +-- [SPARK-29540] Thrift in some cases can't parse string to date +-- SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary; + +-- [SPARK-29540] Thrift in some cases can't parse string to date +-- SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary) FROM empsalary; -- with GROUP BY SELECT four, ten, SUM(SUM(four)) OVER (PARTITION BY four), AVG(ten) FROM tenk1 GROUP BY four, ten ORDER BY four, ten; -SELECT depname, empno, salary, sum(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname); +-- [SPARK-29540] Thrift in some cases can't parse string to date +-- SELECT depname, empno, salary, sum(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname); -- [SPARK-28064] Order by does not accept a call to rank() -- SELECT depname, empno, salary, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary) ORDER BY rank() OVER w; @@ -112,15 +117,17 @@ SELECT avg(four) OVER (PARTITION BY four ORDER BY thousand / 100) FROM tenk1 WHE SELECT ten, two, sum(hundred) AS gsum, sum(sum(hundred)) OVER win AS wsum FROM tenk1 GROUP BY ten, two WINDOW win AS (PARTITION BY two ORDER BY ten); +-- [SPARK-29540] Thrift in some cases can't parse string to date -- more than one window with GROUP BY -SELECT sum(salary), - row_number() OVER (ORDER BY depname), - sum(sum(salary)) OVER (ORDER BY depname DESC) -FROM empsalary GROUP BY depname; +-- SELECT sum(salary), +-- row_number() OVER (ORDER BY depname), +-- sum(sum(salary)) OVER (ORDER BY depname DESC) +-- FROM empsalary GROUP BY depname; +-- [SPARK-29540] Thrift in some cases can't parse string to date -- identical windows with different names -SELECT sum(salary) OVER w1, count(*) OVER w2 -FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary); +-- SELECT sum(salary) OVER w1, count(*) OVER w2 +-- FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary); -- subplan -- [SPARK-28379] Correlated scalar subqueries must be aggregated @@ -130,8 +137,9 @@ FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary); -- empty table SELECT count(*) OVER (PARTITION BY four) FROM (SELECT * FROM tenk1 WHERE FALSE)s; +-- [SPARK-29540] Thrift in some cases can't parse string to date -- mixture of agg/wfunc in the same window -SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC); +-- SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC); -- Cannot safely cast 'enroll_date': StringType to DateType; -- SELECT empno, depname, salary, bonus, depadj, MIN(bonus) OVER (ORDER BY empno), MAX(depadj) OVER () FROM( @@ -338,6 +346,7 @@ SELECT * FROM v_window; -- SELECT * FROM v_window; DROP VIEW v_window; -DROP TABLE empsalary; +-- [SPARK-29540] Thrift in some cases can't parse string to date +-- DROP TABLE empsalary; DROP VIEW tenk2; DROP VIEW int4_tbl; diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out index fb0f2c2501a9e..45bc98ae97640 100644 --- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out +++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part1.sql.out @@ -1,5 +1,5 @@ -- Automatically generated by SQLQueryTestSuite --- Number of queries: 61 +-- Number of queries: 43 -- !query 0 @@ -11,138 +11,11 @@ struct<> -- !query 1 -CREATE TABLE empsalary ( - depname string, - empno integer, - salary int, - enroll_date date -) USING parquet --- !query 1 schema -struct<> --- !query 1 output - - - --- !query 2 -INSERT INTO empsalary VALUES ('develop', 10, 5200, '2007-08-01') --- !query 2 schema -struct<> --- !query 2 output - - - --- !query 3 -INSERT INTO empsalary VALUES ('sales', 1, 5000, '2006-10-01') --- !query 3 schema -struct<> --- !query 3 output - - - --- !query 4 -INSERT INTO empsalary VALUES ('personnel', 5, 3500, '2007-12-10') --- !query 4 schema -struct<> --- !query 4 output - - - --- !query 5 -INSERT INTO empsalary VALUES ('sales', 4, 4800, '2007-08-08') --- !query 5 schema -struct<> --- !query 5 output - - - --- !query 6 -INSERT INTO empsalary VALUES ('personnel', 2, 3900, '2006-12-23') --- !query 6 schema -struct<> --- !query 6 output - - - --- !query 7 -INSERT INTO empsalary VALUES ('develop', 7, 4200, '2008-01-01') --- !query 7 schema -struct<> --- !query 7 output - - - --- !query 8 -INSERT INTO empsalary VALUES ('develop', 9, 4500, '2008-01-01') --- !query 8 schema -struct<> --- !query 8 output - - - --- !query 9 -INSERT INTO empsalary VALUES ('sales', 3, 4800, '2007-08-01') --- !query 9 schema -struct<> --- !query 9 output - - - --- !query 10 -INSERT INTO empsalary VALUES ('develop', 8, 6000, '2006-10-01') --- !query 10 schema -struct<> --- !query 10 output - - - --- !query 11 -INSERT INTO empsalary VALUES ('develop', 11, 5200, '2007-08-15') --- !query 11 schema -struct<> --- !query 11 output - - - --- !query 12 -SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname) FROM empsalary ORDER BY depname, salary --- !query 12 schema -struct --- !query 12 output -develop 7 4200 25100 -develop 9 4500 25100 -develop 10 5200 25100 -develop 11 5200 25100 -develop 8 6000 25100 -personnel 5 3500 7400 -personnel 2 3900 7400 -sales 3 4800 14600 -sales 4 4800 14600 -sales 1 5000 14600 - - --- !query 13 -SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary) FROM empsalary --- !query 13 schema -struct --- !query 13 output -develop 10 5200 3 -develop 11 5200 3 -develop 7 4200 1 -develop 8 6000 5 -develop 9 4500 2 -personnel 2 3900 2 -personnel 5 3500 1 -sales 1 5000 3 -sales 3 4800 1 -sales 4 4800 1 - - --- !query 14 SELECT four, ten, SUM(SUM(four)) OVER (PARTITION BY four), AVG(ten) FROM tenk1 GROUP BY four, ten ORDER BY four, ten --- !query 14 schema +-- !query 1 schema struct --- !query 14 output +-- !query 1 output 0 0 0 0.0 0 2 0 2.0 0 4 0 4.0 @@ -165,28 +38,11 @@ struct --- !query 15 output -develop 10 5200 25100 -develop 11 5200 25100 -develop 7 4200 25100 -develop 8 6000 25100 -develop 9 4500 25100 -personnel 2 3900 7400 -personnel 5 3500 7400 -sales 1 5000 14600 -sales 3 4800 14600 -sales 4 4800 14600 - - --- !query 16 +-- !query 2 SELECT COUNT(*) OVER () FROM tenk1 WHERE unique2 < 10 --- !query 16 schema +-- !query 2 schema struct --- !query 16 output +-- !query 2 output 10 10 10 @@ -199,11 +55,11 @@ struct --- !query 17 output +-- !query 3 output 10 10 10 @@ -216,19 +72,19 @@ struct --- !query 18 output +-- !query 4 output --- !query 19 +-- !query 5 SELECT sum(four) OVER (PARTITION BY ten ORDER BY unique2) AS sum_1, ten, four FROM tenk1 WHERE unique2 < 10 --- !query 19 schema +-- !query 5 schema struct --- !query 19 output +-- !query 5 output 0 0 0 0 0 0 0 4 0 @@ -241,11 +97,11 @@ struct 5 1 1 --- !query 20 +-- !query 6 SELECT row_number() OVER (ORDER BY unique2) FROM tenk1 WHERE unique2 < 10 --- !query 20 schema +-- !query 6 schema struct --- !query 20 output +-- !query 6 output 1 10 2 @@ -258,11 +114,11 @@ struct --- !query 21 output +-- !query 7 output 1 0 0 1 0 0 1 0 2 @@ -275,11 +131,11 @@ struct 4 9 1 --- !query 22 +-- !query 8 SELECT dense_rank() OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 22 schema +-- !query 8 schema struct --- !query 22 output +-- !query 8 output 1 0 0 1 0 0 1 0 2 @@ -292,11 +148,11 @@ struct --- !query 23 output +-- !query 9 output 0.0 0 0 0.0 0 0 0.0 0 2 @@ -309,11 +165,11 @@ struct --- !query 24 output +-- !query 10 output 0.5 1 1 0.5 1 1 0.5 1 3 @@ -326,11 +182,11 @@ struct --- !query 25 output +-- !query 11 output 1 0 0 1 0 0 1 0 2 @@ -343,11 +199,11 @@ struct --- !query 26 output +-- !query 12 output 0 0 0 0 4 0 1 1 1 @@ -360,11 +216,11 @@ NULL 1 1 NULL 1 3 --- !query 27 +-- !query 13 SELECT lead(ten) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 27 schema +-- !query 13 schema struct --- !query 27 output +-- !query 13 output 0 0 0 1 1 1 3 1 3 @@ -377,11 +233,11 @@ NULL 4 0 NULL 9 1 --- !query 28 +-- !query 14 SELECT lead(ten * 2, 1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 28 schema +-- !query 14 schema struct --- !query 28 output +-- !query 14 output 0 0 0 14 1 1 18 7 1 @@ -394,11 +250,11 @@ NULL 4 0 NULL 9 1 --- !query 29 +-- !query 15 SELECT lead(ten * 2, 1, -1) OVER (PARTITION BY four ORDER BY ten), ten, four FROM tenk1 WHERE unique2 < 10 --- !query 29 schema +-- !query 15 schema struct --- !query 29 output +-- !query 15 output -1 0 2 -1 3 3 -1 4 0 @@ -411,11 +267,11 @@ struct --- !query 30 output +-- !query 16 output 0 0 0 0 0 0 0 0 2 @@ -428,11 +284,11 @@ struct --- !query 31 output +-- !query 17 output 0 4 0 1 1 1 1 1 1 @@ -445,13 +301,13 @@ struct --- !query 32 output +-- !query 18 output 4 0 0 4 0 0 4 4 0 @@ -464,12 +320,12 @@ struct --- !query 33 output +-- !query 19 output 0 0 45000 45000 1 1 46000 46000 2 0 47000 92000 @@ -482,11 +338,11 @@ struct 9 1 54000 250000 --- !query 34 +-- !query 20 SELECT count(*) OVER (PARTITION BY four), four FROM (SELECT * FROM tenk1 WHERE two = 1)s WHERE unique2 < 10 --- !query 34 schema +-- !query 20 schema struct --- !query 34 output +-- !query 20 output 2 3 2 3 4 1 @@ -495,13 +351,13 @@ struct --- !query 35 output +-- !query 21 output 136 22 22 @@ -514,7 +370,7 @@ struct 92 --- !query 36 +-- !query 22 SELECT * FROM( SELECT count(*) OVER (PARTITION BY four ORDER BY ten) + sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS total, @@ -522,17 +378,17 @@ SELECT * FROM( sum(hundred) OVER (PARTITION BY two ORDER BY ten) AS twosum FROM tenk1 )sub WHERE total <> fourcount + twosum --- !query 36 schema +-- !query 22 schema struct --- !query 36 output +-- !query 22 output --- !query 37 +-- !query 23 SELECT avg(four) OVER (PARTITION BY four ORDER BY thousand / 100) FROM tenk1 WHERE unique2 < 10 --- !query 37 schema +-- !query 23 schema struct --- !query 37 output +-- !query 23 output 0.0 0.0 0.0 @@ -545,12 +401,12 @@ struct --- !query 38 output +-- !query 24 output 0 0 45000 45000 1 1 46000 46000 2 0 47000 92000 @@ -563,63 +419,15 @@ struct 9 1 54000 250000 --- !query 39 -SELECT sum(salary), - row_number() OVER (ORDER BY depname), - sum(sum(salary)) OVER (ORDER BY depname DESC) -FROM empsalary GROUP BY depname --- !query 39 schema -struct --- !query 39 output -14600 3 14600 -25100 1 47100 -7400 2 22000 - - --- !query 40 -SELECT sum(salary) OVER w1, count(*) OVER w2 -FROM empsalary WINDOW w1 AS (ORDER BY salary), w2 AS (ORDER BY salary) --- !query 40 schema -struct --- !query 40 output -11600 3 -16100 4 -25700 6 -25700 6 -30700 7 -3500 1 -41100 9 -41100 9 -47100 10 -7400 2 - - --- !query 41 +-- !query 25 SELECT count(*) OVER (PARTITION BY four) FROM (SELECT * FROM tenk1 WHERE FALSE)s --- !query 41 schema +-- !query 25 schema struct --- !query 41 output +-- !query 25 output --- !query 42 -SELECT sum(salary) OVER w, rank() OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC) --- !query 42 schema -struct --- !query 42 output -14600 2 -14600 2 -16400 2 -16400 2 -20900 4 -25100 5 -3900 1 -5000 1 -6000 1 -7400 2 - - --- !query 43 +-- !query 26 create temporary view int4_tbl as select * from values (0), (123456), @@ -627,29 +435,29 @@ create temporary view int4_tbl as select * from values (2147483647), (-2147483647) as int4_tbl(f1) --- !query 43 schema +-- !query 26 schema struct<> --- !query 43 output +-- !query 26 output --- !query 44 +-- !query 27 SELECT SUM(COUNT(f1)) OVER () FROM int4_tbl WHERE f1=42 --- !query 44 schema +-- !query 27 schema struct --- !query 44 output +-- !query 27 output 0 --- !query 45 +-- !query 28 select ten, sum(unique1) + sum(unique2) as res, rank() over (order by sum(unique1) + sum(unique2)) as rank from tenk1 group by ten order by ten --- !query 45 schema +-- !query 28 schema struct --- !query 45 output +-- !query 28 output 0 9976146 4 1 10114187 9 2 10059554 8 @@ -662,14 +470,14 @@ struct 9 10040184 7 --- !query 46 +-- !query 29 SELECT four, ten, sum(ten) over (partition by four order by ten), last(ten) over (partition by four order by ten) FROM (select distinct ten, four from tenk1) ss --- !query 46 schema +-- !query 29 schema struct --- !query 46 output +-- !query 29 output 0 0 0 0 0 2 2 2 0 4 6 4 @@ -692,14 +500,14 @@ struct --- !query 47 output +-- !query 30 output 0 0 0 0 0 2 2 2 0 4 6 4 @@ -722,14 +530,14 @@ struct --- !query 48 output +-- !query 31 output 0 0 20 8 0 2 20 8 0 4 20 8 @@ -752,13 +560,13 @@ struct --- !query 49 output +-- !query 32 output 10 3 3 10 7 3 18 2 2 @@ -771,13 +579,13 @@ struct --- !query 50 output +-- !query 33 output 0 0 0 10 3 3 15 5 1 @@ -790,13 +598,13 @@ struct --- !query 51 output +-- !query 34 output 10 0 0 13 2 2 15 7 3 @@ -809,13 +617,13 @@ struct --- !query 52 output +-- !query 35 output 10 0 0 13 3 3 15 8 0 @@ -828,13 +636,13 @@ struct --- !query 53 output +-- !query 36 output 0 7 3 10 5 1 15 8 0 @@ -847,13 +655,13 @@ struct --- !query 54 output +-- !query 37 output 13 1 1 22 6 2 30 9 1 @@ -866,21 +674,21 @@ struct --- !query 55 output +-- !query 38 output --- !query 56 +-- !query 39 SELECT * FROM v_window --- !query 56 schema +-- !query 39 schema struct --- !query 56 output +-- !query 39 output 1 3 10 19 2 6 @@ -893,33 +701,25 @@ struct 9 27 --- !query 57 +-- !query 40 DROP VIEW v_window --- !query 57 schema -struct<> --- !query 57 output - - - --- !query 58 -DROP TABLE empsalary --- !query 58 schema +-- !query 40 schema struct<> --- !query 58 output +-- !query 40 output --- !query 59 +-- !query 41 DROP VIEW tenk2 --- !query 59 schema +-- !query 41 schema struct<> --- !query 59 output +-- !query 41 output --- !query 60 +-- !query 42 DROP VIEW int4_tbl --- !query 60 schema +-- !query 42 schema struct<> --- !query 60 output +-- !query 42 output