Skip to content

Commit

Permalink
feat(over window): support general rank and dense_rank window fun…
Browse files Browse the repository at this point in the history
…ctions (#13183)

Signed-off-by: Richard Chien <[email protected]>
  • Loading branch information
stdrc authored Nov 1, 2023
1 parent 2a6c4aa commit 8ab2f26
Show file tree
Hide file tree
Showing 14 changed files with 644 additions and 427 deletions.
89 changes: 32 additions & 57 deletions e2e_test/over_window/generated/batch/rank_func/mod.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,57 @@

# Test rank window functions including `row_number`, `rank`, `dense_rank`.

include ./row_number_old.slt.part

statement ok
create table t (
id int
, p1 int
, p2 int
, time int
, v1 int
, v2 int
);
create table t (id int, score 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
, row_number() over (partition by 0::int order by score desc, id) as r1
, rank() over (partition by 0::int order by score desc) as r2
, dense_rank() over (partition by 0::int order by score desc) as r3
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
(10001, 95)
, (10002, 90)
, (10003, 80)
, (10004, 95)
, (10005, 90)
, (10006, 90)
, (10007, 96)
;

query iiIII
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
10001 95 2 2 2
10002 90 4 4 3
10003 80 7 7 4
10004 95 3 2 2
10005 90 5 4 3
10006 90 6 4 3
10007 96 1 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
update t set score = 96 where id = 10001;

statement ok
delete from t where time = 2;
delete from t where id = 10006;

query iiiiiii
query iiIII
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
10001 96 1 1 1
10002 90 4 4 3
10003 80 6 6 4
10004 95 3 3 2
10005 90 5 4 3
10007 96 2 1 1

statement ok
drop view v;
Expand Down
89 changes: 32 additions & 57 deletions e2e_test/over_window/generated/streaming/rank_func/mod.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,57 @@

# Test rank window functions including `row_number`, `rank`, `dense_rank`.

include ./row_number_old.slt.part

statement ok
create table t (
id int
, p1 int
, p2 int
, time int
, v1 int
, v2 int
);
create table t (id int, score 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
, row_number() over (partition by 0::int order by score desc, id) as r1
, rank() over (partition by 0::int order by score desc) as r2
, dense_rank() over (partition by 0::int order by score desc) as r3
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
(10001, 95)
, (10002, 90)
, (10003, 80)
, (10004, 95)
, (10005, 90)
, (10006, 90)
, (10007, 96)
;

query iiIII
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
10001 95 2 2 2
10002 90 4 4 3
10003 80 7 7 4
10004 95 3 2 2
10005 90 5 4 3
10006 90 6 4 3
10007 96 1 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
update t set score = 96 where id = 10001;

statement ok
delete from t where time = 2;
delete from t where id = 10006;

query iiiiiii
query iiIII
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
10001 96 1 1 1
10002 90 4 4 3
10003 80 6 6 4
10004 95 3 3 2
10005 90 5 4 3
10007 96 2 1 1

statement ok
drop materialized view v;
Expand Down
89 changes: 32 additions & 57 deletions e2e_test/over_window/templates/rank_func/mod.slt.part
Original file line number Diff line number Diff line change
@@ -1,81 +1,56 @@
# Test rank window functions including `row_number`, `rank`, `dense_rank`.

include ./row_number_old.slt.part

statement ok
create table t (
id int
, p1 int
, p2 int
, time int
, v1 int
, v2 int
);
create table t (id int, score 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
, row_number() over (partition by 0::int order by score desc, id) as r1
, rank() over (partition by 0::int order by score desc) as r2
, dense_rank() over (partition by 0::int order by score desc) as r3
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
(10001, 95)
, (10002, 90)
, (10003, 80)
, (10004, 95)
, (10005, 90)
, (10006, 90)
, (10007, 96)
;

query iiIII
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
10001 95 2 2 2
10002 90 4 4 3
10003 80 7 7 4
10004 95 3 2 2
10005 90 5 4 3
10006 90 6 4 3
10007 96 1 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
update t set score = 96 where id = 10001;

statement ok
delete from t where time = 2;
delete from t where id = 10006;

query iiiiiii
query iiIII
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
10001 96 1 1 1
10002 90 4 4 3
10003 80 6 6 4
10004 95 3 3 2
10005 90 5 4 3
10007 96 2 1 1

statement ok
drop $view_type v;
Expand Down
Loading

0 comments on commit 8ab2f26

Please sign in to comment.