Skip to content

Commit ed643b8

Browse files
authored
feat(over window): window function RANGE frame support - backend part (#14416)
Signed-off-by: Richard Chien <[email protected]>
1 parent fd2a899 commit ed643b8

File tree

24 files changed

+1764
-219
lines changed

24 files changed

+1764
-219
lines changed

e2e_test/over_window/generated/batch/basic/cross_check.slt.part

+40
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ select
2121
from v_a natural join v_c;
2222
----
2323

24+
query i
25+
select
26+
id, out1, out10, out11
27+
from v_a_d
28+
except
29+
select
30+
id, out1, out10, out11
31+
from v_a natural join v_d;
32+
----
33+
2434
query i
2535
select
2636
id, out3, out4, out7, out8, out9
@@ -31,6 +41,26 @@ select
3141
from v_b natural join v_c;
3242
----
3343

44+
query i
45+
select
46+
id, out3, out4, out10, out11
47+
from v_b_d
48+
except
49+
select
50+
id, out3, out4, out10, out11
51+
from v_b natural join v_d;
52+
----
53+
54+
query i
55+
select
56+
id, out7, out8, out9, out10, out11
57+
from v_c_d
58+
except
59+
select
60+
id, out7, out8, out9, out10, out11
61+
from v_c natural join v_d;
62+
----
63+
3464
query i
3565
select
3666
id, out1, out2, out3, out4, out5, out6, out7, out8, out9
@@ -40,3 +70,13 @@ select
4070
id, out1, out2, out3, out4, out5, out6, out7, out8, out9
4171
from v_a natural join v_b natural join v_c;
4272
----
73+
74+
query i
75+
select
76+
id, out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11
77+
from v_a_b_c_d
78+
except
79+
select
80+
id, out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11
81+
from v_a natural join v_b natural join v_c natural join v_d;
82+
----

e2e_test/over_window/generated/batch/basic/mod.slt.part

+35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ select * from v_c order by id;
3535
100003 100 208 2 723 807 723 NULL NULL NULL NULL
3636
100004 103 200 2 702 808 702 NULL NULL NULL NULL
3737

38+
query iiiiiiii
39+
select * from v_d order by id;
40+
----
41+
100001 100 200 1 701 805 1 2124
42+
100002 100 200 2 700 806 1 2124
43+
100003 100 208 2 723 807 1 2124
44+
100004 103 200 2 702 808 2 702
45+
3846
include ./cross_check.slt.part
3947

4048
statement ok
@@ -72,6 +80,16 @@ select * from v_c order by id;
7280
100005 100 200 3 717 810 717 700 700 NULL NULL
7381
100006 105 204 5 703 828 703 NULL NULL NULL NULL
7482

83+
query iiiiiiii
84+
select * from v_d order by id;
85+
----
86+
100001 100 200 1 701 805 1 2124
87+
100002 100 200 2 700 806 1 2841
88+
100003 100 208 2 723 807 1 2841
89+
100004 103 200 2 702 808 2 702
90+
100005 100 200 3 717 810 1 2140
91+
100006 105 204 5 703 828 5 703
92+
7593
include ./cross_check.slt.part
7694

7795
statement ok
@@ -113,6 +131,16 @@ select * from v_c order by id;
113131
100005 100 200 1 717 810 717 723 701 806 806
114132
100006 105 204 5 703 828 703 NULL NULL NULL NULL
115133

134+
query iiiiiiii
135+
select * from v_d order by id;
136+
----
137+
100001 100 200 1 701 805 1 2940
138+
100002 100 200 2 799 806 1 2940
139+
100003 100 200 2 723 807 1 2940
140+
100004 103 200 2 702 808 2 702
141+
100005 100 200 1 717 810 1 2940
142+
100006 105 204 5 703 828 5 703
143+
116144
include ./cross_check.slt.part
117145

118146
statement ok
@@ -139,6 +167,13 @@ select * from v_c order by id;
139167
100005 100 200 1 717 810 717 701 701 NULL NULL
140168
100006 105 204 5 703 828 703 NULL NULL NULL NULL
141169

170+
query iiiiiiii
171+
select * from v_d order by id;
172+
----
173+
100001 100 200 1 701 805 1 1418
174+
100005 100 200 1 717 810 1 1418
175+
100006 105 204 5 703 828 5 703
176+
142177
include ./cross_check.slt.part
143178

144179
include ./teardown.slt.part

e2e_test/over_window/generated/batch/basic/setup.slt.part

+56
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ select
4040
, lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9
4141
from t;
4242

43+
# range frame
44+
statement ok
45+
create view v_d as
46+
select
47+
*
48+
, last_value(time) over (partition by p1 order by time desc range between current row and 2 following) as out10
49+
, sum(v1) over (partition by p1 order by time range between 1 preceding and 1 following) as out11
50+
from t;
51+
4352
statement ok
4453
create view v_a_b as
4554
select
@@ -59,6 +68,15 @@ select
5968
, lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9
6069
from t;
6170

71+
statement ok
72+
create view v_a_d as
73+
select
74+
*
75+
, first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out1
76+
, last_value(time) over (partition by p1 order by time desc range between current row and 2 following) as out10
77+
, sum(v1) over (partition by p1 order by time range between 1 preceding and 1 following) as out11
78+
from t;
79+
6280
statement ok
6381
create view v_b_c as
6482
select
@@ -70,6 +88,27 @@ select
7088
, lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9
7189
from t;
7290

91+
statement ok
92+
create view v_b_d as
93+
select
94+
*
95+
, sum(v1) over (partition by p1, p2 order by time, id rows between unbounded preceding and current row) as out3
96+
, min(v1) over (partition by p1, p2 order by time, id rows between current row and unbounded following) as out4
97+
, last_value(time) over (partition by p1 order by time desc range between current row and 2 following) as out10
98+
, sum(v1) over (partition by p1 order by time range between 1 preceding and 1 following) as out11
99+
from t;
100+
101+
statement ok
102+
create view v_c_d as
103+
select
104+
*
105+
, lag(v1) over (partition by p1, p2 order by time, id) as out7
106+
, lead(v2, 1) over (partition by p1, p2 order by time, id) as out8
107+
, lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9
108+
, last_value(time) over (partition by p1 order by time desc range between current row and 2 following) as out10
109+
, sum(v1) over (partition by p1 order by time range between 1 preceding and 1 following) as out11
110+
from t;
111+
73112
statement ok
74113
create view v_a_b_c as
75114
select
@@ -84,3 +123,20 @@ select
84123
, lead(v2, 1) over (partition by p1, p2 order by time, id) as out8
85124
, lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9
86125
from t;
126+
127+
statement ok
128+
create view v_a_b_c_d as
129+
select
130+
*
131+
, first_value(v1) over (partition by p1, p2 order by time, id rows 3 preceding) as out1
132+
, avg(v1) over (partition by p1) as out2
133+
, sum(v1) over (partition by p1, p2 order by time, id rows between unbounded preceding and current row) as out3
134+
, min(v1) over (partition by p1, p2 order by time, id rows between current row and unbounded following) as out4
135+
, lag(v1, 0) over (partition by p1 order by id) as out5
136+
, lag(v1, 1) over (partition by p1, p2 order by id) as out6
137+
, lag(v1) over (partition by p1, p2 order by time, id) as out7
138+
, lead(v2, 1) over (partition by p1, p2 order by time, id) as out8
139+
, lead(v2, 2) over (partition by p1, p2 order by v1, v2) as out9
140+
, last_value(time) over (partition by p1 order by time desc range between current row and 2 following) as out10
141+
, sum(v1) over (partition by p1 order by time range between 1 preceding and 1 following) as out11
142+
from t;

e2e_test/over_window/generated/batch/basic/teardown.slt.part

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,32 @@ drop view v_b;
99
statement ok
1010
drop view v_c;
1111

12+
statement ok
13+
drop view v_d;
14+
1215
statement ok
1316
drop view v_a_b;
1417

18+
statement ok
19+
drop view v_a_c;
20+
21+
statement ok
22+
drop view v_a_d;
23+
1524
statement ok
1625
drop view v_b_c;
1726

1827
statement ok
19-
drop view v_a_c;
28+
drop view v_b_d;
29+
30+
statement ok
31+
drop view v_c_d;
2032

2133
statement ok
2234
drop view v_a_b_c;
2335

36+
statement ok
37+
drop view v_a_b_c_d;
38+
2439
statement ok
2540
drop table t;

e2e_test/over_window/generated/streaming/basic/cross_check.slt.part

+40
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ select
2121
from v_a natural join v_c;
2222
----
2323

24+
query i
25+
select
26+
id, out1, out10, out11
27+
from v_a_d
28+
except
29+
select
30+
id, out1, out10, out11
31+
from v_a natural join v_d;
32+
----
33+
2434
query i
2535
select
2636
id, out3, out4, out7, out8, out9
@@ -31,6 +41,26 @@ select
3141
from v_b natural join v_c;
3242
----
3343

44+
query i
45+
select
46+
id, out3, out4, out10, out11
47+
from v_b_d
48+
except
49+
select
50+
id, out3, out4, out10, out11
51+
from v_b natural join v_d;
52+
----
53+
54+
query i
55+
select
56+
id, out7, out8, out9, out10, out11
57+
from v_c_d
58+
except
59+
select
60+
id, out7, out8, out9, out10, out11
61+
from v_c natural join v_d;
62+
----
63+
3464
query i
3565
select
3666
id, out1, out2, out3, out4, out5, out6, out7, out8, out9
@@ -40,3 +70,13 @@ select
4070
id, out1, out2, out3, out4, out5, out6, out7, out8, out9
4171
from v_a natural join v_b natural join v_c;
4272
----
73+
74+
query i
75+
select
76+
id, out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11
77+
from v_a_b_c_d
78+
except
79+
select
80+
id, out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11
81+
from v_a natural join v_b natural join v_c natural join v_d;
82+
----

e2e_test/over_window/generated/streaming/basic/mod.slt.part

+35
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ select * from v_c order by id;
3535
100003 100 208 2 723 807 723 NULL NULL NULL NULL
3636
100004 103 200 2 702 808 702 NULL NULL NULL NULL
3737

38+
query iiiiiiii
39+
select * from v_d order by id;
40+
----
41+
100001 100 200 1 701 805 1 2124
42+
100002 100 200 2 700 806 1 2124
43+
100003 100 208 2 723 807 1 2124
44+
100004 103 200 2 702 808 2 702
45+
3846
include ./cross_check.slt.part
3947

4048
statement ok
@@ -72,6 +80,16 @@ select * from v_c order by id;
7280
100005 100 200 3 717 810 717 700 700 NULL NULL
7381
100006 105 204 5 703 828 703 NULL NULL NULL NULL
7482

83+
query iiiiiiii
84+
select * from v_d order by id;
85+
----
86+
100001 100 200 1 701 805 1 2124
87+
100002 100 200 2 700 806 1 2841
88+
100003 100 208 2 723 807 1 2841
89+
100004 103 200 2 702 808 2 702
90+
100005 100 200 3 717 810 1 2140
91+
100006 105 204 5 703 828 5 703
92+
7593
include ./cross_check.slt.part
7694

7795
statement ok
@@ -113,6 +131,16 @@ select * from v_c order by id;
113131
100005 100 200 1 717 810 717 723 701 806 806
114132
100006 105 204 5 703 828 703 NULL NULL NULL NULL
115133

134+
query iiiiiiii
135+
select * from v_d order by id;
136+
----
137+
100001 100 200 1 701 805 1 2940
138+
100002 100 200 2 799 806 1 2940
139+
100003 100 200 2 723 807 1 2940
140+
100004 103 200 2 702 808 2 702
141+
100005 100 200 1 717 810 1 2940
142+
100006 105 204 5 703 828 5 703
143+
116144
include ./cross_check.slt.part
117145

118146
statement ok
@@ -139,6 +167,13 @@ select * from v_c order by id;
139167
100005 100 200 1 717 810 717 701 701 NULL NULL
140168
100006 105 204 5 703 828 703 NULL NULL NULL NULL
141169

170+
query iiiiiiii
171+
select * from v_d order by id;
172+
----
173+
100001 100 200 1 701 805 1 1418
174+
100005 100 200 1 717 810 1 1418
175+
100006 105 204 5 703 828 5 703
176+
142177
include ./cross_check.slt.part
143178

144179
include ./teardown.slt.part

0 commit comments

Comments
 (0)