-
Notifications
You must be signed in to change notification settings - Fork 288
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main 3.0-dev
Commit ID
Other Environment Information
- Hardware parameters:
- OS type:
- Others:Actual Behavior
场景1:
drop table if exists t_lag_test;
create table t_lag_test (id int primary key, val int);
insert into t_lag_test values (1,10),(2,20),(3,30),(4,40),(5,50),(6,60),(7,70),(8,80);
-- lag(val, 1) — 期望: NULL,10,20,30,40,50,60,70
select id, val, lag(val, 1) over (order by id) as lag1 from t_lag_test order by id;
-- lag(val, 3) — 期望: NULL,NULL,NULL,10,20,30,40,50
select id, val, lag(val, 3) over (order by id) as lag3 from t_lag_test order by id;
-- lag(val, 5) — 期望: NULL,NULL,NULL,NULL,NULL,10,20,30
select id, val, lag(val, 5) over (order by id) as lag5 from t_lag_test order by id;
-- lag(val, 1, -1) — 期望: -1,10,20,30,40,50,60,70
select id, val, lag(val, 1, -1) over (order by id) as lag1_def from t_lag_test order by id;
-- lead(val, 3) — 期望: 40,50,60,70,80,NULL,NULL,NULL
select id, val, lead(val, 3) over (order by id) as lead3 from t_lag_test order by id;
-- lead(val, 1, -1) — 期望: 20,30,40,50,60,70,80,-1
select id, val, lead(val, 1, -1) over (order by id) as lead1_def from t_lag_test order by id;
场景2:
drop table if exists t_lag_part;
create table t_lag_part (id int primary key, grp char(1), val int);
insert into t_lag_part values (1,'A',10),(2,'A',20),(3,'A',30),(4,'A',40),
(5,'B',50),(6,'B',60),(7,'B',70),(8,'B',80);
-- lag(val, 2) with partition — BUG
-- 期望 grp=A: NULL,NULL,10,20 grp=B: NULL,NULL,50,60
select id, grp, val,
lag(val, 2) over (partition by grp order by id) as lag2
from t_lag_part order by grp, id;
-- lead(val, 2) with partition — BUG
-- 期望 grp=A: 30,40,NULL,NULL grp=B: 70,80,NULL,NULL
select id, grp, val,
lead(val, 2) over (partition by grp order by id) as lead2
from t_lag_part order by grp, id;
-- lag with default + partition — BUG
-- 期望 grp=A: -1,10,20,30 grp=B: -1,50,60,70
select id, grp, val,
lag(val, 1, -1) over (partition by grp order by id) as lag1_def
from t_lag_part order by grp, id;
Expected Behavior
No response
Steps to Reproduce
as aboveAdditional information
No response