From 32445f19458ccfbc21359c3c5022b09b32f5e196 Mon Sep 17 00:00:00 2001 From: zhangstar333 Date: Wed, 11 Dec 2024 21:08:13 +0800 Subject: [PATCH] update --- .../aggregate_function_window.h | 6 ++-- .../test_first_value_window.out | 20 +++++++++++ .../test_first_value_window.groovy | 36 +++++++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/be/src/vec/aggregate_functions/aggregate_function_window.h b/be/src/vec/aggregate_functions/aggregate_function_window.h index a635cd080e44b0..13fa8e74751df6 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_window.h +++ b/be/src/vec/aggregate_functions/aggregate_function_window.h @@ -465,9 +465,9 @@ struct WindowFunctionFirstImpl : Data { (!arg_ignore_null || (arg_ignore_null && !this->is_null()))) { return; } - if (frame_start <= frame_end && - frame_end <= partition_start) { //rewrite last_value when under partition - this->set_is_null(); //so no need more judge + DCHECK_LE(frame_start, frame_end); + if (frame_start >= partition_end || frame_end <= partition_start) { + this->set_is_null(); return; } frame_start = std::max(frame_start, partition_start); diff --git a/regression-test/data/correctness_p0/test_first_value_window.out b/regression-test/data/correctness_p0/test_first_value_window.out index 22bf1aa51f48e8..73dbcf3ed34eda 100644 --- a/regression-test/data/correctness_p0/test_first_value_window.out +++ b/regression-test/data/correctness_p0/test_first_value_window.out @@ -121,3 +121,23 @@ b 3 3 3 3 3 5 b \N 3 3 3 3 6 b 2 2 2 2 3 7 +-- !select_default8 -- +a 1 2 0 +a \N \N 1 +a \N \N 2 +a 2 \N 3 +b \N 2 4 +b 3 \N 5 +b \N \N 6 +b 2 \N 7 + +-- !select_default9 -- +a 1 2 0 +a \N \N 1 +a \N \N 2 +a 2 \N 3 +b \N 2 4 +b 3 \N 5 +b \N \N 6 +b 2 \N 7 + diff --git a/regression-test/suites/correctness_p0/test_first_value_window.groovy b/regression-test/suites/correctness_p0/test_first_value_window.groovy index b3030c4c44c83e..7c1582e0e61b60 100644 --- a/regression-test/suites/correctness_p0/test_first_value_window.groovy +++ b/regression-test/suites/correctness_p0/test_first_value_window.groovy @@ -312,4 +312,40 @@ suite("test_first_value_window") { ORDER BY uid, time_s ; """ + + qt_select_default8 """ + SELECT uid + ,amt + ,(FIRST_VALUE(amt, true) OVER(PARTITION BY uid ORDER BY time_s ROWS between 3 following AND 6 FOLLOWING)) amt3 + ,time_s + FROM ( + SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 1 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 2 AS time_s UNION ALL + SELECT 'a' AS uid, 2 AS amt, 3 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 4 AS time_s UNION ALL + SELECT 'b' AS uid, 3 AS amt, 5 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 6 AS time_s UNION ALL + SELECT 'b' AS uid, 2 AS amt, 7 AS time_s + ) t + ORDER BY uid, time_s; + """ + + qt_select_default9 """ + SELECT uid + ,amt + ,(FIRST_VALUE(amt) OVER(PARTITION BY uid ORDER BY time_s ROWS between 3 following AND 6 FOLLOWING)) amt3 + ,time_s + FROM ( + SELECT 'a' AS uid, 1 AS amt, 0 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 1 AS time_s UNION ALL + SELECT 'a' AS uid, null AS amt, 2 AS time_s UNION ALL + SELECT 'a' AS uid, 2 AS amt, 3 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 4 AS time_s UNION ALL + SELECT 'b' AS uid, 3 AS amt, 5 AS time_s UNION ALL + SELECT 'b' AS uid, null AS amt, 6 AS time_s UNION ALL + SELECT 'b' AS uid, 2 AS amt, 7 AS time_s + ) t + ORDER BY uid, time_s; + """ }