This is an automated email from the ASF dual-hosted git repository.

zhangstar333 pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 87ecea130b3 [branch-20](bug) fix analytic illegal frame range (#47653)
87ecea130b3 is described below

commit 87ecea130b374ffa610cf8c7795fb6a83011374c
Author: zhangstar333 <zhangs...@selectdb.com>
AuthorDate: Thu Feb 13 10:12:32 2025 +0800

    [branch-20](bug) fix analytic illegal frame range (#47653)
    
    ### What problem does this PR solve?
    Related PR: #(https://github.com/apache/doris/pull/41147)
---
 .../aggregate_function_window.h                    |   6 ++--
 be/src/vec/exec/vanalytic_eval_node.cpp            |   2 ++
 .../data/nereids_syntax_p0/window_function.out     | Bin 2221 -> 3101 bytes
 .../nereids_syntax_p0/window_function.groovy       |  34 +++++++++++++++++++++
 4 files changed, 39 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 a615f3e985f..e054337bcb1 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_window.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_window.h
@@ -386,9 +386,9 @@ template <typename Data, bool arg_ignore_null = false>
 struct WindowFunctionLastImpl : Data {
     void add_range_single_place(int64_t partition_start, int64_t 
partition_end, int64_t frame_start,
                                 int64_t frame_end, const IColumn** columns) {
-        if ((frame_start <= frame_end) &&
-            ((frame_end <= partition_start) ||
-             (frame_start >= partition_end))) { //beyond or under partition, 
set null
+        DCHECK_LE(frame_start, frame_end);
+        if ((frame_end <= partition_start) ||
+            (frame_start >= partition_end)) { //beyond or under partition, set 
null
             this->set_is_null();
             return;
         }
diff --git a/be/src/vec/exec/vanalytic_eval_node.cpp 
b/be/src/vec/exec/vanalytic_eval_node.cpp
index c31e65b8c1d..3d95f138bac 100644
--- a/be/src/vec/exec/vanalytic_eval_node.cpp
+++ b/be/src/vec/exec/vanalytic_eval_node.cpp
@@ -383,6 +383,8 @@ Status VAnalyticEvalNode::_get_next_for_rows(size_t 
current_block_rows) {
                 range_start = _current_row_position + _rows_start_offset;
             }
             range_end = _current_row_position + _rows_end_offset + 1;
+            // Make sure range_start <= range_end
+            range_start = std::min(range_start, range_end);
         }
         _executor.execute(_partition_by_start.pos, _partition_by_end.pos, 
range_start, range_end);
         _executor.insert_result(current_block_rows);
diff --git a/regression-test/data/nereids_syntax_p0/window_function.out 
b/regression-test/data/nereids_syntax_p0/window_function.out
index 9eb74e68552..ed550e13f1e 100644
Binary files a/regression-test/data/nereids_syntax_p0/window_function.out and 
b/regression-test/data/nereids_syntax_p0/window_function.out differ
diff --git a/regression-test/suites/nereids_syntax_p0/window_function.groovy 
b/regression-test/suites/nereids_syntax_p0/window_function.groovy
index e4c4b2a2aeb..04703948340 100644
--- a/regression-test/suites/nereids_syntax_p0/window_function.groovy
+++ b/regression-test/suites/nereids_syntax_p0/window_function.groovy
@@ -217,4 +217,38 @@ suite("window_function") {
         sql "select group_concat(xwho order by xwhat) over(partition by xwhen) 
from test_normalize_window;"
         exception "order by is not supported"
     }
+
+    sql "drop table if exists 
table_200_undef_partitions2_keys3_properties4_distributed_by54"
+    sql """create table 
table_200_undef_partitions2_keys3_properties4_distributed_by54 (
+            pk int,
+            col_char_255__undef_signed char(255)  null  ,
+            col_char_100__undef_signed char(100)  null  ,
+            col_char_255__undef_signed_not_null char(255)  not null  ,
+            col_char_100__undef_signed_not_null char(100)  not null  ,
+            col_varchar_255__undef_signed varchar(255)  null  ,
+            col_varchar_255__undef_signed_not_null varchar(255)  not null  ,
+            col_varchar_1000__undef_signed varchar(1000)  null  ,
+            col_varchar_1000__undef_signed_not_null varchar(1000)  not null  ,
+            col_varchar_1001__undef_signed varchar(1001)  null  ,
+            col_varchar_1001__undef_signed_not_null varchar(1001)  not null  ,
+            col_string_undef_signed string  null  ,
+            col_string_undef_signed_not_null string  not null  
+            ) engine=olap
+            DUPLICATE KEY(pk, col_char_255__undef_signed, 
col_char_100__undef_signed)
+            distributed by hash(pk) buckets 10
+            properties("replication_num" = "1", "bloom_filter_columns" = 
"col_char_255__undef_signed, col_char_100__undef_signed, 
col_varchar_255__undef_signed ")
+    """
+
+    sql """ insert into 
table_200_undef_partitions2_keys3_properties4_distributed_by54(pk,col_char_255__undef_signed,col_char_255__undef_signed_not_null,col_char_100__undef_signed,col_char_100__undef_signed_not_null,col_varchar_255__undef_signed,col_varchar_255__undef_signed_not_null,col_varchar_1000__undef_signed,col_varchar_1000__undef_signed_not_null,col_varchar_1001__undef_signed,col_varchar_1001__undef_signed_not_null,col_string_undef_signed,col_string_undef_signed_not_null)
 values  [...]
+
+    qt_select_last """ select
+        LAST_VALUE(col_char_100__undef_signed, false) over (
+            partition by col_char_255__undef_signed
+            order by 
+                pk asc rows between unbounded preceding
+                and 3 preceding
+        )
+    from
+        table_200_undef_partitions2_keys3_properties4_distributed_by54 order 
by 1;"""
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to