Skip to content

Commit

Permalink
add e2e test for the failed case
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chien <stdrc@outlook.com>
  • Loading branch information
stdrc committed Sep 23, 2024
1 parent cc81eaf commit 32637bf
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions e2e_test/udf/bug_fixes/17560_udaf_as_win_func.slt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,69 @@ select t.value, sum00(weight) OVER (PARTITION BY value) from (values (1, 1), (nu
----
1 1
3 3

statement ok
drop aggregate sum00;

# https://github.com/risingwavelabs/risingwave/issues/18436

statement ok
CREATE TABLE exam_scores (
score_id int,
exam_id int,
student_id int,
score real,
exam_date timestamp
);

statement ok
INSERT INTO exam_scores (score_id, exam_id, student_id, score, exam_date)
VALUES
(1, 101, 1001, 85.5, '2022-01-10'),
(2, 101, 1002, 92.0, '2022-01-10'),
(3, 101, 1003, 78.5, '2022-01-10'),
(4, 102, 1001, 91.2, '2022-02-15'),
(5, 102, 1003, 88.9, '2022-02-15');

statement ok
create aggregate weighted_avg(value float, weight float) returns float language python as $$
def create_state():
return (0, 0)
def accumulate(state, value, weight):
if value is None or weight is None:
return state
(s, w) = state
s += value * weight
w += weight
return (s, w)
def retract(state, value, weight):
if value is None or weight is None:
return state
(s, w) = state
s -= value * weight
w -= weight
return (s, w)
def finish(state):
(sum, weight) = state
if weight == 0:
return None
else:
return sum / weight
$$;

query
SELECT
*,
weighted_avg(score, 1) OVER (
PARTITION BY "student_id"
ORDER BY "exam_date"
ROWS 2 PRECEDING
) AS "weighted_avg"
FROM exam_scores
ORDER BY "student_id", "exam_date";
----
1 101 1001 85.5 2022-01-10 00:00:00 85.5
4 102 1001 91.2 2022-02-15 00:00:00 88.3499984741211
2 101 1002 92 2022-01-10 00:00:00 92
3 101 1003 78.5 2022-01-10 00:00:00 78.5
5 102 1003 88.9 2022-02-15 00:00:00 83.70000076293945

0 comments on commit 32637bf

Please sign in to comment.