From b7195f85aee70c318f908268c2e53d899a8045af Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Wed, 1 Nov 2023 13:57:17 +0800 Subject: [PATCH] refactor(test): reorganize over window e2e tests (#13186) Signed-off-by: Richard Chien --- e2e_test/batch/over_window/generated | 1 + e2e_test/batch/over_window/main.slt.part | 6 +- e2e_test/batch/over_window/over_window | 1 - .../over_window/special_cases/mod.slt.part | 1 - e2e_test/over_window/gen.py | 20 +++-- .../batch/agg_in_win_func/mod.slt.part | 80 +++++++++++++++++ .../batch/{ => basic}/cross_check.slt.part | 0 .../generated/batch/{ => basic}/mod.slt.part | 86 +------------------ .../{create.slt.part => basic/setup.slt.part} | 30 ------- .../teardown.slt.part} | 9 -- .../batch/expr_in_win_func/mod.slt.part | 71 +++++++++++++++ .../over_window/generated/batch/main.slt.part | 10 +++ .../opt_agg_then_join.slt.part/mod.slt.part} | 42 ++++++++- .../generated/batch/rank_func/mod.slt.part | 86 +++++++++++++++++++ .../streaming/agg_in_win_func/mod.slt.part | 80 +++++++++++++++++ .../{ => basic}/cross_check.slt.part | 0 .../streaming/{ => basic}/mod.slt.part | 86 +------------------ .../{create.slt.part => basic/setup.slt.part} | 30 ------- .../teardown.slt.part} | 9 -- .../streaming/expr_in_win_func/mod.slt.part | 71 +++++++++++++++ .../generated/streaming/main.slt.part | 10 +++ .../opt_agg_then_join.slt.part/mod.slt.part | 74 ++++++++++++++++ .../streaming/rank_func/mod.slt.part | 86 +++++++++++++++++++ .../templates/agg_in_win_func/mod.slt.part | 78 +++++++++++++++++ .../{ => basic}/cross_check.slt.part | 0 .../templates/{ => basic}/mod.slt.part | 86 +------------------ .../{create.slt.part => basic/setup.slt.part} | 30 ------- .../teardown.slt.part} | 9 -- .../templates/expr_in_win_func/mod.slt.part | 69 +++++++++++++++ e2e_test/over_window/templates/main.slt.part | 8 ++ .../opt_agg_then_join.slt.part/mod.slt.part} | 10 ++- .../templates/rank_func/mod.slt.part | 84 ++++++++++++++++++ e2e_test/streaming/over_window/generated | 1 + e2e_test/streaming/over_window/main.slt | 6 +- e2e_test/streaming/over_window/over_window | 1 - .../over_window/special_cases/mod.slt.part | 1 - 36 files changed, 882 insertions(+), 390 deletions(-) create mode 120000 e2e_test/batch/over_window/generated delete mode 120000 e2e_test/batch/over_window/over_window delete mode 100644 e2e_test/batch/over_window/special_cases/mod.slt.part create mode 100644 e2e_test/over_window/generated/batch/agg_in_win_func/mod.slt.part rename e2e_test/over_window/generated/batch/{ => basic}/cross_check.slt.part (100%) rename e2e_test/over_window/generated/batch/{ => basic}/mod.slt.part (68%) rename e2e_test/over_window/generated/batch/{create.slt.part => basic/setup.slt.part} (79%) rename e2e_test/over_window/generated/batch/{drop.slt.part => basic/teardown.slt.part} (77%) create mode 100644 e2e_test/over_window/generated/batch/expr_in_win_func/mod.slt.part create mode 100644 e2e_test/over_window/generated/batch/main.slt.part rename e2e_test/{batch/over_window/special_cases/to_agg_then_join.slt.part => over_window/generated/batch/opt_agg_then_join.slt.part/mod.slt.part} (54%) create mode 100644 e2e_test/over_window/generated/batch/rank_func/mod.slt.part create mode 100644 e2e_test/over_window/generated/streaming/agg_in_win_func/mod.slt.part rename e2e_test/over_window/generated/streaming/{ => basic}/cross_check.slt.part (100%) rename e2e_test/over_window/generated/streaming/{ => basic}/mod.slt.part (68%) rename e2e_test/over_window/generated/streaming/{create.slt.part => basic/setup.slt.part} (78%) rename e2e_test/over_window/generated/streaming/{drop.slt.part => basic/teardown.slt.part} (75%) create mode 100644 e2e_test/over_window/generated/streaming/expr_in_win_func/mod.slt.part create mode 100644 e2e_test/over_window/generated/streaming/main.slt.part create mode 100644 e2e_test/over_window/generated/streaming/opt_agg_then_join.slt.part/mod.slt.part create mode 100644 e2e_test/over_window/generated/streaming/rank_func/mod.slt.part create mode 100644 e2e_test/over_window/templates/agg_in_win_func/mod.slt.part rename e2e_test/over_window/templates/{ => basic}/cross_check.slt.part (100%) rename e2e_test/over_window/templates/{ => basic}/mod.slt.part (68%) rename e2e_test/over_window/templates/{create.slt.part => basic/setup.slt.part} (78%) rename e2e_test/over_window/templates/{drop.slt.part => basic/teardown.slt.part} (72%) create mode 100644 e2e_test/over_window/templates/expr_in_win_func/mod.slt.part create mode 100644 e2e_test/over_window/templates/main.slt.part rename e2e_test/{streaming/over_window/special_cases/to_agg_then_join.slt.part => over_window/templates/opt_agg_then_join.slt.part/mod.slt.part} (86%) create mode 100644 e2e_test/over_window/templates/rank_func/mod.slt.part create mode 120000 e2e_test/streaming/over_window/generated delete mode 120000 e2e_test/streaming/over_window/over_window delete mode 100644 e2e_test/streaming/over_window/special_cases/mod.slt.part diff --git a/e2e_test/batch/over_window/generated b/e2e_test/batch/over_window/generated new file mode 120000 index 0000000000000..32dfe679fac64 --- /dev/null +++ b/e2e_test/batch/over_window/generated @@ -0,0 +1 @@ +../../over_window/generated/batch/ \ No newline at end of file diff --git a/e2e_test/batch/over_window/main.slt.part b/e2e_test/batch/over_window/main.slt.part index 6e277352059c4..dca370c0306ee 100644 --- a/e2e_test/batch/over_window/main.slt.part +++ b/e2e_test/batch/over_window/main.slt.part @@ -1,5 +1 @@ -statement ok -SET RW_IMPLICIT_FLUSH TO true; - -include ./special_cases/mod.slt.part -include ./over_window/mod.slt.part +include ./generated/main.slt.part diff --git a/e2e_test/batch/over_window/over_window b/e2e_test/batch/over_window/over_window deleted file mode 120000 index f3208bd4500bc..0000000000000 --- a/e2e_test/batch/over_window/over_window +++ /dev/null @@ -1 +0,0 @@ -../../over_window/generated/batch \ No newline at end of file diff --git a/e2e_test/batch/over_window/special_cases/mod.slt.part b/e2e_test/batch/over_window/special_cases/mod.slt.part deleted file mode 100644 index 265ed4966619f..0000000000000 --- a/e2e_test/batch/over_window/special_cases/mod.slt.part +++ /dev/null @@ -1 +0,0 @@ -include ./to_agg_then_join.slt.part diff --git a/e2e_test/over_window/gen.py b/e2e_test/over_window/gen.py index bd30d998d83fc..af4bec4790c5b 100755 --- a/e2e_test/over_window/gen.py +++ b/e2e_test/over_window/gen.py @@ -25,19 +25,27 @@ shutil.rmtree(mode_dir) os.makedirs(mode_dir, exist_ok=True) -for file in os.listdir(templates_dir): - if not file.endswith(".slt") and not file.endswith(".slt.part"): - continue - print(f"Generating `{file}`...") +def render(filepath: str): + relpath = path.relpath(filepath, templates_dir) + print(f"Rendering `{relpath}`...") - with open(path.join(templates_dir, file), "r") as f: + with open(path.join(templates_dir, relpath), "r") as f: tpl = Template(f.read()) for mode, context in contexts.items(): - out_file = path.join(generated_dir, mode, file) + out_file = path.join(generated_dir, mode, relpath) + os.makedirs(path.dirname(out_file), exist_ok=True) with open(out_file, "w") as f: f.write(file_head + "\n\n") f.write(tpl.safe_substitute(context)) + +for dirpath, dirnames, filenames in os.walk(templates_dir): + for filename in filenames: + if not filename.endswith(".slt") and not filename.endswith(".slt.part"): + continue + render(path.join(dirpath, filename)) + + print("Done.") diff --git a/e2e_test/over_window/generated/batch/agg_in_win_func/mod.slt.part b/e2e_test/over_window/generated/batch/agg_in_win_func/mod.slt.part new file mode 100644 index 0000000000000..ff53636e393ac --- /dev/null +++ b/e2e_test/over_window/generated/batch/agg_in_win_func/mod.slt.part @@ -0,0 +1,80 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test aggregate function calls as window function args/PARTITION BY/ORDER BY. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create view v as +select + p1, p2 + , row_number() over (partition by p1 order by p2) as out1 + , sum(sum(v2)) over (partition by p1, avg(time) order by max(v1), p2) as out2 +from t +group by p1, p2; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +query iiii +select * from v order by p1, p2; +---- +100 200 1 1611 +100 208 2 807 +103 200 1 808 + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +query iiii +select * from v order by p1, p2; +---- +100 200 1 2421 +100 208 2 3228 +103 200 1 808 +105 204 1 828 + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiii +select * from v order by p1, p2; +---- +100 200 1 3228 +103 200 1 808 +105 204 1 828 + +statement ok +delete from t where time = 2; + +query iiii +select * from v order by p1, p2; +---- +100 200 1 1615 +105 204 1 828 + +statement ok +drop view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/generated/batch/cross_check.slt.part b/e2e_test/over_window/generated/batch/basic/cross_check.slt.part similarity index 100% rename from e2e_test/over_window/generated/batch/cross_check.slt.part rename to e2e_test/over_window/generated/batch/basic/cross_check.slt.part diff --git a/e2e_test/over_window/generated/batch/mod.slt.part b/e2e_test/over_window/generated/batch/basic/mod.slt.part similarity index 68% rename from e2e_test/over_window/generated/batch/mod.slt.part rename to e2e_test/over_window/generated/batch/basic/mod.slt.part index 2c7778fd46aff..a8c74b16bf790 100644 --- a/e2e_test/over_window/generated/batch/mod.slt.part +++ b/e2e_test/over_window/generated/batch/basic/mod.slt.part @@ -1,6 +1,8 @@ # This file is generated by `gen.py`. Do not edit it manually! -include ./create.slt.part +# Test basic functionality of general batch and streaming over window. + +include ./setup.slt.part statement ok insert into t values @@ -33,21 +35,6 @@ select * from v_c order by id; 100003 100 208 2 723 807 723 NULL NULL NULL NULL 100004 103 200 2 702 808 702 NULL NULL NULL NULL -query II -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 2 -100002 100 200 2 700 806 2 3 -100003 100 208 2 723 807 3 1 -100004 103 200 2 702 808 1 1 - -query iiii -select * from v_e order by p1; ----- -100 200 1 1611 -100 208 2 807 -103 200 1 808 - include ./cross_check.slt.part statement ok @@ -85,24 +72,6 @@ select * from v_c order by id; 100005 100 200 3 717 810 717 700 700 NULL NULL 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query II -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 2 -100002 100 200 2 700 806 2 3 -100003 100 208 2 723 807 3 1 -100004 103 200 2 702 808 1 1 -100005 100 200 3 717 810 4 4 -100006 105 204 5 703 828 1 1 - -query iiii -select * from v_e order by p1, p2; ----- -100 200 1 2421 -100 208 2 3228 -103 200 1 808 -105 204 1 828 - include ./cross_check.slt.part statement ok @@ -144,33 +113,6 @@ select * from v_c order by id; 100005 100 200 1 717 810 717 723 701 806 806 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query iiiiiii -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 1 -100002 100 200 2 799 806 3 2 -100003 100 200 2 723 807 4 3 -100004 103 200 2 702 808 1 1 -100005 100 200 1 717 810 2 4 -100006 105 204 5 703 828 1 1 - -query iiiiiii -select * from v_e order by p1; ----- -100 200 1 3228 -103 200 1 808 -105 204 1 828 - -query iiiiiiiiii -select * from v_expr order by id; ----- -100001 100 200 1 701 805 805 0 701 NULL 1402 -100002 100 200 2 799 806 806 0 701 703 1446 -100003 100 200 2 723 807 807 0 701 801 1446 -100004 103 200 2 702 808 808 0 702 NULL 1404 -100005 100 200 1 717 810 810 0 701 725 1434 -100006 105 204 5 703 828 828 0 703 NULL 1406 - include ./cross_check.slt.part statement ok @@ -197,26 +139,6 @@ select * from v_c order by id; 100005 100 200 1 717 810 717 701 701 NULL NULL 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query iiiiiii -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 1 -100005 100 200 1 717 810 2 2 -100006 105 204 5 703 828 1 1 - -query iiii -select * from v_e order by p1; ----- -100 200 1 1615 -105 204 1 828 - -query iiiiiiiiii -select * from v_expr order by id; ----- -100001 100 200 1 701 805 805 0 701 NULL 1402 -100005 100 200 1 717 810 810 0 701 703 1434 -100006 105 204 5 703 828 828 0 703 NULL 1406 - include ./cross_check.slt.part -include ./drop.slt.part +include ./teardown.slt.part diff --git a/e2e_test/over_window/generated/batch/create.slt.part b/e2e_test/over_window/generated/batch/basic/setup.slt.part similarity index 79% rename from e2e_test/over_window/generated/batch/create.slt.part rename to e2e_test/over_window/generated/batch/basic/setup.slt.part index 5f4b5e1152804..2ffc1b055334d 100644 --- a/e2e_test/over_window/generated/batch/create.slt.part +++ b/e2e_test/over_window/generated/batch/basic/setup.slt.part @@ -40,25 +40,6 @@ select , lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9 from t; -# row_number -statement ok -create view v_d as -select - * - , row_number() over (partition by p1 order by time, id) as out10 - , row_number() over (partition by p1 order by p2 desc, id) as out11 -from t; - -# over + agg -statement ok -create view v_e as -select - p1, p2 - , row_number() over (partition by p1 order by p2) as out12 - , sum(sum(v2)) over (partition by p1, avg(time) order by max(v1), p2) as out13 -from t -group by p1, p2; - statement ok create view v_a_b as select @@ -103,14 +84,3 @@ select , lead(v2, 1) over (partition by p1, p2 order by time, id) as out8 , lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9 from t; - -statement ok -create view v_expr as -select - * - , t.v2 as out1 - , 0 as out2 - , first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out3 - , lag(v1 + 2, 0 + 1) over (partition by p1 - 1 order by id) as out4 - , min(v1 * 2) over (partition by p1, p2 order by time + 1, id rows between current row and unbounded following) as out5 -from t; diff --git a/e2e_test/over_window/generated/batch/drop.slt.part b/e2e_test/over_window/generated/batch/basic/teardown.slt.part similarity index 77% rename from e2e_test/over_window/generated/batch/drop.slt.part rename to e2e_test/over_window/generated/batch/basic/teardown.slt.part index 435ffd46433e7..97f416dd49c9e 100644 --- a/e2e_test/over_window/generated/batch/drop.slt.part +++ b/e2e_test/over_window/generated/batch/basic/teardown.slt.part @@ -9,12 +9,6 @@ drop view v_b; statement ok drop view v_c; -statement ok -drop view v_d; - -statement ok -drop view v_e; - statement ok drop view v_a_b; @@ -27,8 +21,5 @@ drop view v_a_c; statement ok drop view v_a_b_c; -statement ok -drop view v_expr; - statement ok drop table t; diff --git a/e2e_test/over_window/generated/batch/expr_in_win_func/mod.slt.part b/e2e_test/over_window/generated/batch/expr_in_win_func/mod.slt.part new file mode 100644 index 0000000000000..653881de2c920 --- /dev/null +++ b/e2e_test/over_window/generated/batch/expr_in_win_func/mod.slt.part @@ -0,0 +1,71 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test expressions as window function args/PARTITION BY/ORDER BY. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create view v as +select + * + , t.v2 as out1 + , 0 as out2 + , first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out3 + , lag(v1 + 2, 0 + 1) over (partition by p1 - 1 order by id) as out4 + , min(v1 * 2) over (partition by p1, p2 order by time + 1, id rows between current row and unbounded following) as out5 +from t; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 805 0 701 NULL 1402 +100002 100 200 2 799 806 806 0 701 703 1446 +100003 100 200 2 723 807 807 0 701 801 1446 +100004 103 200 2 702 808 808 0 702 NULL 1404 +100005 100 200 1 717 810 810 0 701 725 1434 +100006 105 204 5 703 828 828 0 703 NULL 1406 + +statement ok +delete from t where time = 2; + +query iiiiiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 805 0 701 NULL 1402 +100005 100 200 1 717 810 810 0 701 703 1434 +100006 105 204 5 703 828 828 0 703 NULL 1406 + +statement ok +drop view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/generated/batch/main.slt.part b/e2e_test/over_window/generated/batch/main.slt.part new file mode 100644 index 0000000000000..9f0ad1baeffe3 --- /dev/null +++ b/e2e_test/over_window/generated/batch/main.slt.part @@ -0,0 +1,10 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +statement ok +SET RW_IMPLICIT_FLUSH TO true; + +include ./basic/mod.slt.part +include ./rank_func/mod.slt.part +include ./expr_in_win_func/mod.slt.part +include ./agg_in_win_func/mod.slt.part +include ./opt_agg_then_join/mod.slt.part diff --git a/e2e_test/batch/over_window/special_cases/to_agg_then_join.slt.part b/e2e_test/over_window/generated/batch/opt_agg_then_join.slt.part/mod.slt.part similarity index 54% rename from e2e_test/batch/over_window/special_cases/to_agg_then_join.slt.part rename to e2e_test/over_window/generated/batch/opt_agg_then_join.slt.part/mod.slt.part index e2545f9d69ed3..023946c6d4327 100644 --- a/e2e_test/batch/over_window/special_cases/to_agg_then_join.slt.part +++ b/e2e_test/over_window/generated/batch/opt_agg_then_join.slt.part/mod.slt.part @@ -1,9 +1,14 @@ -statement ok -SET RW_IMPLICIT_FLUSH TO true; +# This file is generated by `gen.py`. Do not edit it manually! + +# Test cases that should be optimized to Agg + Join. statement ok create table t(x int, y int); +statement ok +create view v as +select *, sum(y / x) OVER (PARTITION BY x) as a, count(x) OVER (PARTITION BY y) as b from t; + statement ok insert into t values (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), @@ -13,7 +18,7 @@ insert into t values (1, 3), (2, 3), (3, 3); query IIII rowsort -select *, sum(y / x) OVER (PARTITION BY x) as a, count(x) OVER (PARTITION BY y) as b from t; +select * from v; ---- 1 1 18 3 1 2 18 3 @@ -34,5 +39,36 @@ select *, sum(y / x) OVER (PARTITION BY x) as a, count(x) OVER (PARTITION BY y) 3 4 4 3 3 5 4 3 +statement ok +insert into t values (1, 6), (2, 8), (3, 12); + +query IIII rowsort +select * from v; +---- +1 1 24 3 +1 2 24 3 +1 3 24 6 +1 3 24 6 +1 4 24 3 +1 5 24 3 +1 6 24 1 +2 1 11 3 +2 2 11 3 +2 3 11 6 +2 3 11 6 +2 4 11 3 +2 5 11 3 +2 8 11 1 +3 1 8 3 +3 12 8 1 +3 2 8 3 +3 3 8 6 +3 3 8 6 +3 4 8 3 +3 5 8 3 + +statement ok +drop view v; + statement ok drop table t; diff --git a/e2e_test/over_window/generated/batch/rank_func/mod.slt.part b/e2e_test/over_window/generated/batch/rank_func/mod.slt.part new file mode 100644 index 0000000000000..58e434bd11362 --- /dev/null +++ b/e2e_test/over_window/generated/batch/rank_func/mod.slt.part @@ -0,0 +1,86 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test rank window functions including `row_number`, `rank`, `dense_rank`. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create view v as +select + * + , row_number() over (partition by p1 order by time, id) as out1 + , row_number() over (partition by p1 order by p2 desc, id) as out2 +from t; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +query II +select * from v order by id; +---- +100001 100 200 1 701 805 1 2 +100002 100 200 2 700 806 2 3 +100003 100 208 2 723 807 3 1 +100004 103 200 2 702 808 1 1 + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +query II +select * from v order by id; +---- +100001 100 200 1 701 805 1 2 +100002 100 200 2 700 806 2 3 +100003 100 208 2 723 807 3 1 +100004 103 200 2 702 808 1 1 +100005 100 200 3 717 810 4 4 +100006 105 204 5 703 828 1 1 + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 1 1 +100002 100 200 2 799 806 3 2 +100003 100 200 2 723 807 4 3 +100004 103 200 2 702 808 1 1 +100005 100 200 1 717 810 2 4 +100006 105 204 5 703 828 1 1 + +statement ok +delete from t where time = 2; + +query iiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 1 1 +100005 100 200 1 717 810 2 2 +100006 105 204 5 703 828 1 1 + +statement ok +drop view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/generated/streaming/agg_in_win_func/mod.slt.part b/e2e_test/over_window/generated/streaming/agg_in_win_func/mod.slt.part new file mode 100644 index 0000000000000..1cf5cb3951ef0 --- /dev/null +++ b/e2e_test/over_window/generated/streaming/agg_in_win_func/mod.slt.part @@ -0,0 +1,80 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test aggregate function calls as window function args/PARTITION BY/ORDER BY. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create materialized view v as +select + p1, p2 + , row_number() over (partition by p1 order by p2) as out1 + , sum(sum(v2)) over (partition by p1, avg(time) order by max(v1), p2) as out2 +from t +group by p1, p2; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +query iiii +select * from v order by p1, p2; +---- +100 200 1 1611 +100 208 2 807 +103 200 1 808 + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +query iiii +select * from v order by p1, p2; +---- +100 200 1 2421 +100 208 2 3228 +103 200 1 808 +105 204 1 828 + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiii +select * from v order by p1, p2; +---- +100 200 1 3228 +103 200 1 808 +105 204 1 828 + +statement ok +delete from t where time = 2; + +query iiii +select * from v order by p1, p2; +---- +100 200 1 1615 +105 204 1 828 + +statement ok +drop materialized view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/generated/streaming/cross_check.slt.part b/e2e_test/over_window/generated/streaming/basic/cross_check.slt.part similarity index 100% rename from e2e_test/over_window/generated/streaming/cross_check.slt.part rename to e2e_test/over_window/generated/streaming/basic/cross_check.slt.part diff --git a/e2e_test/over_window/generated/streaming/mod.slt.part b/e2e_test/over_window/generated/streaming/basic/mod.slt.part similarity index 68% rename from e2e_test/over_window/generated/streaming/mod.slt.part rename to e2e_test/over_window/generated/streaming/basic/mod.slt.part index 2c7778fd46aff..a8c74b16bf790 100644 --- a/e2e_test/over_window/generated/streaming/mod.slt.part +++ b/e2e_test/over_window/generated/streaming/basic/mod.slt.part @@ -1,6 +1,8 @@ # This file is generated by `gen.py`. Do not edit it manually! -include ./create.slt.part +# Test basic functionality of general batch and streaming over window. + +include ./setup.slt.part statement ok insert into t values @@ -33,21 +35,6 @@ select * from v_c order by id; 100003 100 208 2 723 807 723 NULL NULL NULL NULL 100004 103 200 2 702 808 702 NULL NULL NULL NULL -query II -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 2 -100002 100 200 2 700 806 2 3 -100003 100 208 2 723 807 3 1 -100004 103 200 2 702 808 1 1 - -query iiii -select * from v_e order by p1; ----- -100 200 1 1611 -100 208 2 807 -103 200 1 808 - include ./cross_check.slt.part statement ok @@ -85,24 +72,6 @@ select * from v_c order by id; 100005 100 200 3 717 810 717 700 700 NULL NULL 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query II -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 2 -100002 100 200 2 700 806 2 3 -100003 100 208 2 723 807 3 1 -100004 103 200 2 702 808 1 1 -100005 100 200 3 717 810 4 4 -100006 105 204 5 703 828 1 1 - -query iiii -select * from v_e order by p1, p2; ----- -100 200 1 2421 -100 208 2 3228 -103 200 1 808 -105 204 1 828 - include ./cross_check.slt.part statement ok @@ -144,33 +113,6 @@ select * from v_c order by id; 100005 100 200 1 717 810 717 723 701 806 806 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query iiiiiii -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 1 -100002 100 200 2 799 806 3 2 -100003 100 200 2 723 807 4 3 -100004 103 200 2 702 808 1 1 -100005 100 200 1 717 810 2 4 -100006 105 204 5 703 828 1 1 - -query iiiiiii -select * from v_e order by p1; ----- -100 200 1 3228 -103 200 1 808 -105 204 1 828 - -query iiiiiiiiii -select * from v_expr order by id; ----- -100001 100 200 1 701 805 805 0 701 NULL 1402 -100002 100 200 2 799 806 806 0 701 703 1446 -100003 100 200 2 723 807 807 0 701 801 1446 -100004 103 200 2 702 808 808 0 702 NULL 1404 -100005 100 200 1 717 810 810 0 701 725 1434 -100006 105 204 5 703 828 828 0 703 NULL 1406 - include ./cross_check.slt.part statement ok @@ -197,26 +139,6 @@ select * from v_c order by id; 100005 100 200 1 717 810 717 701 701 NULL NULL 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query iiiiiii -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 1 -100005 100 200 1 717 810 2 2 -100006 105 204 5 703 828 1 1 - -query iiii -select * from v_e order by p1; ----- -100 200 1 1615 -105 204 1 828 - -query iiiiiiiiii -select * from v_expr order by id; ----- -100001 100 200 1 701 805 805 0 701 NULL 1402 -100005 100 200 1 717 810 810 0 701 703 1434 -100006 105 204 5 703 828 828 0 703 NULL 1406 - include ./cross_check.slt.part -include ./drop.slt.part +include ./teardown.slt.part diff --git a/e2e_test/over_window/generated/streaming/create.slt.part b/e2e_test/over_window/generated/streaming/basic/setup.slt.part similarity index 78% rename from e2e_test/over_window/generated/streaming/create.slt.part rename to e2e_test/over_window/generated/streaming/basic/setup.slt.part index 4334fb1cdd30e..cc46c4066f0f4 100644 --- a/e2e_test/over_window/generated/streaming/create.slt.part +++ b/e2e_test/over_window/generated/streaming/basic/setup.slt.part @@ -40,25 +40,6 @@ select , lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9 from t; -# row_number -statement ok -create materialized view v_d as -select - * - , row_number() over (partition by p1 order by time, id) as out10 - , row_number() over (partition by p1 order by p2 desc, id) as out11 -from t; - -# over + agg -statement ok -create materialized view v_e as -select - p1, p2 - , row_number() over (partition by p1 order by p2) as out12 - , sum(sum(v2)) over (partition by p1, avg(time) order by max(v1), p2) as out13 -from t -group by p1, p2; - statement ok create materialized view v_a_b as select @@ -103,14 +84,3 @@ select , lead(v2, 1) over (partition by p1, p2 order by time, id) as out8 , lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9 from t; - -statement ok -create materialized view v_expr as -select - * - , t.v2 as out1 - , 0 as out2 - , first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out3 - , lag(v1 + 2, 0 + 1) over (partition by p1 - 1 order by id) as out4 - , min(v1 * 2) over (partition by p1, p2 order by time + 1, id rows between current row and unbounded following) as out5 -from t; diff --git a/e2e_test/over_window/generated/streaming/drop.slt.part b/e2e_test/over_window/generated/streaming/basic/teardown.slt.part similarity index 75% rename from e2e_test/over_window/generated/streaming/drop.slt.part rename to e2e_test/over_window/generated/streaming/basic/teardown.slt.part index e6c4fcfaad244..2089fefcac249 100644 --- a/e2e_test/over_window/generated/streaming/drop.slt.part +++ b/e2e_test/over_window/generated/streaming/basic/teardown.slt.part @@ -9,12 +9,6 @@ drop materialized view v_b; statement ok drop materialized view v_c; -statement ok -drop materialized view v_d; - -statement ok -drop materialized view v_e; - statement ok drop materialized view v_a_b; @@ -27,8 +21,5 @@ drop materialized view v_a_c; statement ok drop materialized view v_a_b_c; -statement ok -drop materialized view v_expr; - statement ok drop table t; diff --git a/e2e_test/over_window/generated/streaming/expr_in_win_func/mod.slt.part b/e2e_test/over_window/generated/streaming/expr_in_win_func/mod.slt.part new file mode 100644 index 0000000000000..89584947e8c33 --- /dev/null +++ b/e2e_test/over_window/generated/streaming/expr_in_win_func/mod.slt.part @@ -0,0 +1,71 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test expressions as window function args/PARTITION BY/ORDER BY. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create materialized view v as +select + * + , t.v2 as out1 + , 0 as out2 + , first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out3 + , lag(v1 + 2, 0 + 1) over (partition by p1 - 1 order by id) as out4 + , min(v1 * 2) over (partition by p1, p2 order by time + 1, id rows between current row and unbounded following) as out5 +from t; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 805 0 701 NULL 1402 +100002 100 200 2 799 806 806 0 701 703 1446 +100003 100 200 2 723 807 807 0 701 801 1446 +100004 103 200 2 702 808 808 0 702 NULL 1404 +100005 100 200 1 717 810 810 0 701 725 1434 +100006 105 204 5 703 828 828 0 703 NULL 1406 + +statement ok +delete from t where time = 2; + +query iiiiiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 805 0 701 NULL 1402 +100005 100 200 1 717 810 810 0 701 703 1434 +100006 105 204 5 703 828 828 0 703 NULL 1406 + +statement ok +drop materialized view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/generated/streaming/main.slt.part b/e2e_test/over_window/generated/streaming/main.slt.part new file mode 100644 index 0000000000000..9f0ad1baeffe3 --- /dev/null +++ b/e2e_test/over_window/generated/streaming/main.slt.part @@ -0,0 +1,10 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +statement ok +SET RW_IMPLICIT_FLUSH TO true; + +include ./basic/mod.slt.part +include ./rank_func/mod.slt.part +include ./expr_in_win_func/mod.slt.part +include ./agg_in_win_func/mod.slt.part +include ./opt_agg_then_join/mod.slt.part diff --git a/e2e_test/over_window/generated/streaming/opt_agg_then_join.slt.part/mod.slt.part b/e2e_test/over_window/generated/streaming/opt_agg_then_join.slt.part/mod.slt.part new file mode 100644 index 0000000000000..5a131ddd2029a --- /dev/null +++ b/e2e_test/over_window/generated/streaming/opt_agg_then_join.slt.part/mod.slt.part @@ -0,0 +1,74 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test cases that should be optimized to Agg + Join. + +statement ok +create table t(x int, y int); + +statement ok +create materialized view v as +select *, sum(y / x) OVER (PARTITION BY x) as a, count(x) OVER (PARTITION BY y) as b from t; + +statement ok +insert into t values + (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), + (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), + (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), + -- ties + (1, 3), (2, 3), (3, 3); + +query IIII rowsort +select * from v; +---- +1 1 18 3 +1 2 18 3 +1 3 18 6 +1 3 18 6 +1 4 18 3 +1 5 18 3 +2 1 7 3 +2 2 7 3 +2 3 7 6 +2 3 7 6 +2 4 7 3 +2 5 7 3 +3 1 4 3 +3 2 4 3 +3 3 4 6 +3 3 4 6 +3 4 4 3 +3 5 4 3 + +statement ok +insert into t values (1, 6), (2, 8), (3, 12); + +query IIII rowsort +select * from v; +---- +1 1 24 3 +1 2 24 3 +1 3 24 6 +1 3 24 6 +1 4 24 3 +1 5 24 3 +1 6 24 1 +2 1 11 3 +2 2 11 3 +2 3 11 6 +2 3 11 6 +2 4 11 3 +2 5 11 3 +2 8 11 1 +3 1 8 3 +3 12 8 1 +3 2 8 3 +3 3 8 6 +3 3 8 6 +3 4 8 3 +3 5 8 3 + +statement ok +drop materialized view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/generated/streaming/rank_func/mod.slt.part b/e2e_test/over_window/generated/streaming/rank_func/mod.slt.part new file mode 100644 index 0000000000000..1a22f59053e9d --- /dev/null +++ b/e2e_test/over_window/generated/streaming/rank_func/mod.slt.part @@ -0,0 +1,86 @@ +# This file is generated by `gen.py`. Do not edit it manually! + +# Test rank window functions including `row_number`, `rank`, `dense_rank`. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create materialized view v as +select + * + , row_number() over (partition by p1 order by time, id) as out1 + , row_number() over (partition by p1 order by p2 desc, id) as out2 +from t; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +query II +select * from v order by id; +---- +100001 100 200 1 701 805 1 2 +100002 100 200 2 700 806 2 3 +100003 100 208 2 723 807 3 1 +100004 103 200 2 702 808 1 1 + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +query II +select * from v order by id; +---- +100001 100 200 1 701 805 1 2 +100002 100 200 2 700 806 2 3 +100003 100 208 2 723 807 3 1 +100004 103 200 2 702 808 1 1 +100005 100 200 3 717 810 4 4 +100006 105 204 5 703 828 1 1 + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 1 1 +100002 100 200 2 799 806 3 2 +100003 100 200 2 723 807 4 3 +100004 103 200 2 702 808 1 1 +100005 100 200 1 717 810 2 4 +100006 105 204 5 703 828 1 1 + +statement ok +delete from t where time = 2; + +query iiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 1 1 +100005 100 200 1 717 810 2 2 +100006 105 204 5 703 828 1 1 + +statement ok +drop materialized view v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/templates/agg_in_win_func/mod.slt.part b/e2e_test/over_window/templates/agg_in_win_func/mod.slt.part new file mode 100644 index 0000000000000..742fe034b9eb0 --- /dev/null +++ b/e2e_test/over_window/templates/agg_in_win_func/mod.slt.part @@ -0,0 +1,78 @@ +# Test aggregate function calls as window function args/PARTITION BY/ORDER BY. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create $view_type v as +select + p1, p2 + , row_number() over (partition by p1 order by p2) as out1 + , sum(sum(v2)) over (partition by p1, avg(time) order by max(v1), p2) as out2 +from t +group by p1, p2; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +query iiii +select * from v order by p1, p2; +---- +100 200 1 1611 +100 208 2 807 +103 200 1 808 + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +query iiii +select * from v order by p1, p2; +---- +100 200 1 2421 +100 208 2 3228 +103 200 1 808 +105 204 1 828 + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiii +select * from v order by p1, p2; +---- +100 200 1 3228 +103 200 1 808 +105 204 1 828 + +statement ok +delete from t where time = 2; + +query iiii +select * from v order by p1, p2; +---- +100 200 1 1615 +105 204 1 828 + +statement ok +drop $view_type v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/templates/cross_check.slt.part b/e2e_test/over_window/templates/basic/cross_check.slt.part similarity index 100% rename from e2e_test/over_window/templates/cross_check.slt.part rename to e2e_test/over_window/templates/basic/cross_check.slt.part diff --git a/e2e_test/over_window/templates/mod.slt.part b/e2e_test/over_window/templates/basic/mod.slt.part similarity index 68% rename from e2e_test/over_window/templates/mod.slt.part rename to e2e_test/over_window/templates/basic/mod.slt.part index 1b1b86a0d40d3..421f5a911f468 100644 --- a/e2e_test/over_window/templates/mod.slt.part +++ b/e2e_test/over_window/templates/basic/mod.slt.part @@ -1,4 +1,6 @@ -include ./create.slt.part +# Test basic functionality of general batch and streaming over window. + +include ./setup.slt.part statement ok insert into t values @@ -31,21 +33,6 @@ select * from v_c order by id; 100003 100 208 2 723 807 723 NULL NULL NULL NULL 100004 103 200 2 702 808 702 NULL NULL NULL NULL -query II -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 2 -100002 100 200 2 700 806 2 3 -100003 100 208 2 723 807 3 1 -100004 103 200 2 702 808 1 1 - -query iiii -select * from v_e order by p1; ----- -100 200 1 1611 -100 208 2 807 -103 200 1 808 - include ./cross_check.slt.part statement ok @@ -83,24 +70,6 @@ select * from v_c order by id; 100005 100 200 3 717 810 717 700 700 NULL NULL 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query II -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 2 -100002 100 200 2 700 806 2 3 -100003 100 208 2 723 807 3 1 -100004 103 200 2 702 808 1 1 -100005 100 200 3 717 810 4 4 -100006 105 204 5 703 828 1 1 - -query iiii -select * from v_e order by p1, p2; ----- -100 200 1 2421 -100 208 2 3228 -103 200 1 808 -105 204 1 828 - include ./cross_check.slt.part statement ok @@ -142,33 +111,6 @@ select * from v_c order by id; 100005 100 200 1 717 810 717 723 701 806 806 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query iiiiiii -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 1 -100002 100 200 2 799 806 3 2 -100003 100 200 2 723 807 4 3 -100004 103 200 2 702 808 1 1 -100005 100 200 1 717 810 2 4 -100006 105 204 5 703 828 1 1 - -query iiiiiii -select * from v_e order by p1; ----- -100 200 1 3228 -103 200 1 808 -105 204 1 828 - -query iiiiiiiiii -select * from v_expr order by id; ----- -100001 100 200 1 701 805 805 0 701 NULL 1402 -100002 100 200 2 799 806 806 0 701 703 1446 -100003 100 200 2 723 807 807 0 701 801 1446 -100004 103 200 2 702 808 808 0 702 NULL 1404 -100005 100 200 1 717 810 810 0 701 725 1434 -100006 105 204 5 703 828 828 0 703 NULL 1406 - include ./cross_check.slt.part statement ok @@ -195,26 +137,6 @@ select * from v_c order by id; 100005 100 200 1 717 810 717 701 701 NULL NULL 100006 105 204 5 703 828 703 NULL NULL NULL NULL -query iiiiiii -select * from v_d order by id; ----- -100001 100 200 1 701 805 1 1 -100005 100 200 1 717 810 2 2 -100006 105 204 5 703 828 1 1 - -query iiii -select * from v_e order by p1; ----- -100 200 1 1615 -105 204 1 828 - -query iiiiiiiiii -select * from v_expr order by id; ----- -100001 100 200 1 701 805 805 0 701 NULL 1402 -100005 100 200 1 717 810 810 0 701 703 1434 -100006 105 204 5 703 828 828 0 703 NULL 1406 - include ./cross_check.slt.part -include ./drop.slt.part +include ./teardown.slt.part diff --git a/e2e_test/over_window/templates/create.slt.part b/e2e_test/over_window/templates/basic/setup.slt.part similarity index 78% rename from e2e_test/over_window/templates/create.slt.part rename to e2e_test/over_window/templates/basic/setup.slt.part index 7ac749e459b02..d989d50029430 100644 --- a/e2e_test/over_window/templates/create.slt.part +++ b/e2e_test/over_window/templates/basic/setup.slt.part @@ -38,25 +38,6 @@ select , lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9 from t; -# row_number -statement ok -create $view_type v_d as -select - * - , row_number() over (partition by p1 order by time, id) as out10 - , row_number() over (partition by p1 order by p2 desc, id) as out11 -from t; - -# over + agg -statement ok -create $view_type v_e as -select - p1, p2 - , row_number() over (partition by p1 order by p2) as out12 - , sum(sum(v2)) over (partition by p1, avg(time) order by max(v1), p2) as out13 -from t -group by p1, p2; - statement ok create $view_type v_a_b as select @@ -101,14 +82,3 @@ select , lead(v2, 1) over (partition by p1, p2 order by time, id) as out8 , lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9 from t; - -statement ok -create $view_type v_expr as -select - * - , t.v2 as out1 - , 0 as out2 - , first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out3 - , lag(v1 + 2, 0 + 1) over (partition by p1 - 1 order by id) as out4 - , min(v1 * 2) over (partition by p1, p2 order by time + 1, id rows between current row and unbounded following) as out5 -from t; diff --git a/e2e_test/over_window/templates/drop.slt.part b/e2e_test/over_window/templates/basic/teardown.slt.part similarity index 72% rename from e2e_test/over_window/templates/drop.slt.part rename to e2e_test/over_window/templates/basic/teardown.slt.part index def8e92379878..89915395703ad 100644 --- a/e2e_test/over_window/templates/drop.slt.part +++ b/e2e_test/over_window/templates/basic/teardown.slt.part @@ -7,12 +7,6 @@ drop $view_type v_b; statement ok drop $view_type v_c; -statement ok -drop $view_type v_d; - -statement ok -drop $view_type v_e; - statement ok drop $view_type v_a_b; @@ -25,8 +19,5 @@ drop $view_type v_a_c; statement ok drop $view_type v_a_b_c; -statement ok -drop $view_type v_expr; - statement ok drop table t; diff --git a/e2e_test/over_window/templates/expr_in_win_func/mod.slt.part b/e2e_test/over_window/templates/expr_in_win_func/mod.slt.part new file mode 100644 index 0000000000000..bdc71711c631b --- /dev/null +++ b/e2e_test/over_window/templates/expr_in_win_func/mod.slt.part @@ -0,0 +1,69 @@ +# Test expressions as window function args/PARTITION BY/ORDER BY. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create $view_type v as +select + * + , t.v2 as out1 + , 0 as out2 + , first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out3 + , lag(v1 + 2, 0 + 1) over (partition by p1 - 1 order by id) as out4 + , min(v1 * 2) over (partition by p1, p2 order by time + 1, id rows between current row and unbounded following) as out5 +from t; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 805 0 701 NULL 1402 +100002 100 200 2 799 806 806 0 701 703 1446 +100003 100 200 2 723 807 807 0 701 801 1446 +100004 103 200 2 702 808 808 0 702 NULL 1404 +100005 100 200 1 717 810 810 0 701 725 1434 +100006 105 204 5 703 828 828 0 703 NULL 1406 + +statement ok +delete from t where time = 2; + +query iiiiiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 805 0 701 NULL 1402 +100005 100 200 1 717 810 810 0 701 703 1434 +100006 105 204 5 703 828 828 0 703 NULL 1406 + +statement ok +drop $view_type v; + +statement ok +drop table t; diff --git a/e2e_test/over_window/templates/main.slt.part b/e2e_test/over_window/templates/main.slt.part new file mode 100644 index 0000000000000..00dfac5101eee --- /dev/null +++ b/e2e_test/over_window/templates/main.slt.part @@ -0,0 +1,8 @@ +statement ok +SET RW_IMPLICIT_FLUSH TO true; + +include ./basic/mod.slt.part +include ./rank_func/mod.slt.part +include ./expr_in_win_func/mod.slt.part +include ./agg_in_win_func/mod.slt.part +include ./opt_agg_then_join/mod.slt.part diff --git a/e2e_test/streaming/over_window/special_cases/to_agg_then_join.slt.part b/e2e_test/over_window/templates/opt_agg_then_join.slt.part/mod.slt.part similarity index 86% rename from e2e_test/streaming/over_window/special_cases/to_agg_then_join.slt.part rename to e2e_test/over_window/templates/opt_agg_then_join.slt.part/mod.slt.part index aa428234dcb6d..75aa93b2f4f1f 100644 --- a/e2e_test/streaming/over_window/special_cases/to_agg_then_join.slt.part +++ b/e2e_test/over_window/templates/opt_agg_then_join.slt.part/mod.slt.part @@ -1,8 +1,10 @@ +# Test cases that should be optimized to Agg + Join. + statement ok create table t(x int, y int); statement ok -create materialized view mv as +create $view_type v as select *, sum(y / x) OVER (PARTITION BY x) as a, count(x) OVER (PARTITION BY y) as b from t; statement ok @@ -14,7 +16,7 @@ insert into t values (1, 3), (2, 3), (3, 3); query IIII rowsort -select * from mv; +select * from v; ---- 1 1 18 3 1 2 18 3 @@ -39,7 +41,7 @@ statement ok insert into t values (1, 6), (2, 8), (3, 12); query IIII rowsort -select * from mv; +select * from v; ---- 1 1 24 3 1 2 24 3 @@ -64,7 +66,7 @@ select * from mv; 3 5 8 3 statement ok -drop materialized view mv; +drop $view_type v; statement ok drop table t; diff --git a/e2e_test/over_window/templates/rank_func/mod.slt.part b/e2e_test/over_window/templates/rank_func/mod.slt.part new file mode 100644 index 0000000000000..b654819f8e0f0 --- /dev/null +++ b/e2e_test/over_window/templates/rank_func/mod.slt.part @@ -0,0 +1,84 @@ +# Test rank window functions including `row_number`, `rank`, `dense_rank`. + +statement ok +create table t ( + id int + , p1 int + , p2 int + , time int + , v1 int + , v2 int +); + +statement ok +create $view_type v as +select + * + , row_number() over (partition by p1 order by time, id) as out1 + , row_number() over (partition by p1 order by p2 desc, id) as out2 +from t; + +statement ok +insert into t values + (100001, 100, 200, 1, 701, 805) +, (100002, 100, 200, 2, 700, 806) +, (100003, 100, 208, 2, 723, 807) +, (100004, 103, 200, 2, 702, 808); + +query II +select * from v order by id; +---- +100001 100 200 1 701 805 1 2 +100002 100 200 2 700 806 2 3 +100003 100 208 2 723 807 3 1 +100004 103 200 2 702 808 1 1 + +statement ok +insert into t values + (100005, 100, 200, 3, 717, 810) +, (100006, 105, 204, 5, 703, 828); + +query II +select * from v order by id; +---- +100001 100 200 1 701 805 1 2 +100002 100 200 2 700 806 2 3 +100003 100 208 2 723 807 3 1 +100004 103 200 2 702 808 1 1 +100005 100 200 3 717 810 4 4 +100006 105 204 5 703 828 1 1 + +statement ok +update t set v1 = 799 where id = 100002; -- value change + +statement ok +update t set p2 = 200 where id = 100003; -- partition change + +statement ok +update t set "time" = 1 where id = 100005; -- order change + +query iiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 1 1 +100002 100 200 2 799 806 3 2 +100003 100 200 2 723 807 4 3 +100004 103 200 2 702 808 1 1 +100005 100 200 1 717 810 2 4 +100006 105 204 5 703 828 1 1 + +statement ok +delete from t where time = 2; + +query iiiiiii +select * from v order by id; +---- +100001 100 200 1 701 805 1 1 +100005 100 200 1 717 810 2 2 +100006 105 204 5 703 828 1 1 + +statement ok +drop $view_type v; + +statement ok +drop table t; diff --git a/e2e_test/streaming/over_window/generated b/e2e_test/streaming/over_window/generated new file mode 120000 index 0000000000000..747efa5c83183 --- /dev/null +++ b/e2e_test/streaming/over_window/generated @@ -0,0 +1 @@ +../../over_window/generated/streaming/ \ No newline at end of file diff --git a/e2e_test/streaming/over_window/main.slt b/e2e_test/streaming/over_window/main.slt index 6e277352059c4..dca370c0306ee 100644 --- a/e2e_test/streaming/over_window/main.slt +++ b/e2e_test/streaming/over_window/main.slt @@ -1,5 +1 @@ -statement ok -SET RW_IMPLICIT_FLUSH TO true; - -include ./special_cases/mod.slt.part -include ./over_window/mod.slt.part +include ./generated/main.slt.part diff --git a/e2e_test/streaming/over_window/over_window b/e2e_test/streaming/over_window/over_window deleted file mode 120000 index 2efb728950ba5..0000000000000 --- a/e2e_test/streaming/over_window/over_window +++ /dev/null @@ -1 +0,0 @@ -../../over_window/generated/streaming \ No newline at end of file diff --git a/e2e_test/streaming/over_window/special_cases/mod.slt.part b/e2e_test/streaming/over_window/special_cases/mod.slt.part deleted file mode 100644 index 265ed4966619f..0000000000000 --- a/e2e_test/streaming/over_window/special_cases/mod.slt.part +++ /dev/null @@ -1 +0,0 @@ -include ./to_agg_then_join.slt.part