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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 8704618a2ba [fix](window function) Fix illegal frame range (#41147) 
(#41306)
8704618a2ba is described below

commit 8704618a2bac1d56ccfe424da5c39f6f06d2c178
Author: Gabriel <gabrielleeb...@gmail.com>
AuthorDate: Wed Sep 25 21:09:25 2024 +0800

    [fix](window function) Fix illegal frame range (#41147) (#41306)
    
    pick #41147
    
    0# doris::signal::(anonymous namespace)::FailureSignalHandler(int,
    siginfo_t*, void*) at
    
    /home/zcp/repo_center/doris_master/doris/be/src/common/signal_handler.h:421
     1# 0x00007F591D573520 in /lib/x86_64-linux-gnu/libc.so.6
     2# pthread_kill at ./nptl/pthread_kill.c:89
     3# raise at ../sysdeps/posix/raise.c:27
     4# abort at ./stdlib/abort.c:81
     5# _nl_load_domain at ./intl/loadmsgcat.c:1177
     6# 0x00007F591D56AE96 in /lib/x86_64-linux-gnu/libc.so.6
    7# doris::vectorized::PODArray<unsigned char, 4096ul, Allocator<false,
    false, false, DefaultMemoryAllocator>, 16ul, 15ul>::operator[](long)
    const at
    
    /home/zcp/repo_center/doris_master/doris/be/src/vec/common/pod_array.h:365
    8# doris::vectorized::ColumnNullable::is_null_at(unsigned long) const at
    
/home/zcp/repo_center/doris_master/doris/be/src/vec/columns/column_nullable.h:158
    9#
    
    
doris::vectorized::ReaderFirstAndLastData<doris::vectorized::ColumnVector<double>,
    true, true, false>::insert_result_into(doris::vectorized::IColumn&)
    const at
    
    
/home/zcp/repo_center/doris_master/doris/be/src/vec/aggregate_functions/aggregate_function_reader_first_last.h:125
    10# doris::pipeline::AnalyticLocalState::_insert_result_info(long) in
    /mnt/hdd01/PERFORMANCE_ENV/be/lib/doris_be
    11# std::_Function_handler<void (long), std::_Bind_result<void, void
    
(doris::pipeline::AnalyticLocalState::*(doris::pipeline::AnalyticLocalState*,
    std::_Placeholder<1>))(long)> >::_M_invoke(std::_Any_data const&,
    long&&) at
    
    
/var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:291
    12# std::function<void (long)>::operator()(long) const at
    
/var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:560
    13# doris::pipeline::AnalyticLocalState::_get_next_for_rows(unsigned
    long) in /mnt/hdd01/PERFORMANCE_ENV/be/lib/doris_be 14#
    std::enable_if<is_invocable_r_v<doris::Status, doris::Status
    (doris::pipeline::AnalyticLocalState::*&)(unsigned long),
    doris::pipeline::AnalyticLocalState*&, unsigned long>,
    doris::Status>::type std::__invoke_r<doris::Status, doris::Status
    (doris::pipeline::AnalyticLocalState::*&)(unsigned long),
    doris::pipeline::AnalyticLocalState*&, unsigned long>(doris::Status
    (doris::pipeline::AnalyticLocalState::*&)(unsigned long),
    doris::pipeline::AnalyticLocalState*&, unsigned long&&) at
    
/var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:114
    15# doris::Status std::_Bind_result<doris::Status, doris::Status
    
(doris::pipeline::AnalyticLocalState::*(doris::pipeline::AnalyticLocalState*,
    std::_Placeholder<1>))(unsigned long)>::__call<doris::Status, unsigned
    long&&, 0ul, 1ul>(std::tuple<unsigned long&&>&&, std::_Index_tuple<0ul,
    1ul>) at
    
    
/var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/functional:570
    16# std::_Function_handler<doris::Status (unsigned long),
    std::_Bind_result<doris::Status, doris::Status
    
    
(doris::pipeline::AnalyticLocalState::*(doris::pipeline::AnalyticLocalState*,
    std::_Placeholder<1>))(unsigned long)> >::_M_invoke(std::_Any_data
    const&, unsigned long&&) at
    
    
/var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:291
    17# std::function<doris::Status (unsigned long)>::operator()(unsigned
    long) const at
    
    
/var/local/ldb-toolchain/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:560
    18#
    
    doris::pipeline::AnalyticSourceOperatorX::get_block(doris::RuntimeState*,
    doris::vectorized::Block*, bool*) in
    /mnt/hdd01/PERFORMANCE_ENV/be/lib/doris_be
    19#
    
    
doris::pipeline::OperatorXBase::get_block_after_projects(doris::RuntimeState*,
    doris::vectorized::Block*, bool*) at
    
    
/home/zcp/repo_center/doris_master/doris/be/src/pipeline/exec/operator.cpp:322
    20# doris::pipeline::PipelineTask::execute(bool*) in
    /mnt/hdd01/PERFORMANCE_ENV/be/lib/doris_be
    21# doris::pipeline::TaskScheduler::_do_work(unsigned long) at
    
/home/zcp/repo_center/doris_master/doris/be/src/pipeline/task_scheduler.cpp:138
    22# doris::ThreadPool::dispatch_thread() in
    /mnt/hdd01/PERFORMANCE_ENV/be/lib/doris_be
    23# doris::Thread::supervise_thread(void*) at
    /home/zcp/repo_center/doris_master/doris/be/src/util/thread.cpp:499 24#
    start_thread at ./nptl/pthread_create.c:442
    25# 0x00007F591D657850 at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:83
    
    ## Proposed changes
    
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 be/src/pipeline/exec/analytic_source_operator.cpp  |   4 +-
 .../aggregate_function_window.h                    |   6 +-
 .../data/nereids_syntax_p0/window_function.out     | 202 +++++++++++++++++++++
 .../nereids_syntax_p0/window_function.groovy       |  39 ++++
 4 files changed, 247 insertions(+), 4 deletions(-)

diff --git a/be/src/pipeline/exec/analytic_source_operator.cpp 
b/be/src/pipeline/exec/analytic_source_operator.cpp
index 3583642273b..b3e692cdd95 100644
--- a/be/src/pipeline/exec/analytic_source_operator.cpp
+++ b/be/src/pipeline/exec/analytic_source_operator.cpp
@@ -355,6 +355,7 @@ Status AnalyticLocalState::_get_next_for_rows(size_t 
current_block_rows) {
                         1; //going on calculate,add up data, no need to reset 
state
         } else {
             _reset_agg_status();
+            range_end = _shared_state->current_row_position + _rows_end_offset 
+ 1;
             if (!_parent->cast<AnalyticSourceOperatorX>()
                          ._window.__isset
                          .window_start) { //[preceding, offset]        
--unbound: [preceding, following]
@@ -362,7 +363,8 @@ Status AnalyticLocalState::_get_next_for_rows(size_t 
current_block_rows) {
             } else {
                 range_start = _shared_state->current_row_position + 
_rows_start_offset;
             }
-            range_end = _shared_state->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, 
_shared_state->partition_by_end.pos, range_start,
                           range_end);
diff --git a/be/src/vec/aggregate_functions/aggregate_function_window.h 
b/be/src/vec/aggregate_functions/aggregate_function_window.h
index ec1aab99e6a..92e22c895c4 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_window.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_window.h
@@ -499,9 +499,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/regression-test/data/nereids_syntax_p0/window_function.out 
b/regression-test/data/nereids_syntax_p0/window_function.out
index 5e91a4682d1..4ec92fc61ad 100644
--- a/regression-test/data/nereids_syntax_p0/window_function.out
+++ b/regression-test/data/nereids_syntax_p0/window_function.out
@@ -359,3 +359,205 @@
 1.0
 1.5
 
+-- !sql --
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+
diff --git a/regression-test/suites/nereids_syntax_p0/window_function.groovy 
b/regression-test/suites/nereids_syntax_p0/window_function.groovy
index 209729b9358..9a427d10198 100644
--- a/regression-test/suites/nereids_syntax_p0/window_function.groovy
+++ b/regression-test/suites/nereids_syntax_p0/window_function.groovy
@@ -201,4 +201,43 @@ suite("window_function") {
               from
               (select 1 as dt,2 as dt2)t
         group by dt,dt2"""
+
+    sql """ DROP TABLE IF EXISTS 
table_200_undef_partitions2_keys3_properties4_distributed_by53 """
+    sql """
+    create table 
table_200_undef_partitions2_keys3_properties4_distributed_by53 (
+    pk int,
+    col_boolean_undef_signed boolean  null  ,
+    col_boolean_undef_signed_not_null boolean  not null  ,
+    col_tinyint_undef_signed tinyint  null  ,
+    col_tinyint_undef_signed_not_null tinyint  not null  ,
+    col_smallint_undef_signed smallint  null  ,
+    col_smallint_undef_signed_not_null smallint  not null  ,
+    col_int_undef_signed int  null  ,
+    col_int_undef_signed_not_null int  not null  ,
+    col_bigint_undef_signed bigint  null  ,
+    col_bigint_undef_signed_not_null bigint  not null  ,
+    col_float_undef_signed float  null  ,
+    col_float_undef_signed_not_null float  not null  ,
+    col_double_undef_signed double  null  ,
+    col_double_undef_signed_not_null double  not null  ,
+    col_decimal_10_0__undef_signed decimal(10,0)  null  ,
+    col_decimal_10_0__undef_signed_not_null decimal(10,0)  not null  ,
+    col_decimal_16_10__undef_signed decimal(16,10)  null  ,
+    col_decimal_16_10__undef_signed_not_null decimal(16,10)  not null  ,
+    col_decimal_37__12__undef_signed decimal(37, 12)  null  ,
+    col_decimal_37__12__undef_signed_not_null decimal(37, 12)  not null  ,
+    col_decimal_17_0__undef_signed decimal(17,0)  null  ,
+    col_decimal_17_0__undef_signed_not_null decimal(17,0)  not null  ,
+    col_decimal_8_4__undef_signed decimal(8,4)  null  ,
+    col_decimal_8_4__undef_signed_not_null decimal(8,4)  not null  ,
+    col_decimal_9_0__undef_signed decimal(9,0)  null  ,
+    col_decimal_9_0__undef_signed_not_null decimal(9,0)  not null
+    ) engine=olap
+    UNIQUE KEY(pk)
+    distributed by hash(pk) buckets 10
+    properties("replication_num" = "1");
+    insert into 
table_200_undef_partitions2_keys3_properties4_distributed_by53(pk,col_boolean_undef_signed,col_boolean_undef_signed_not_null,col_tinyint_undef_signed,col_tinyint_undef_signed_not_null,col_smallint_undef_signed,col_smallint_undef_signed_not_null,col_int_undef_signed,col_int_undef_signed_not_null,col_bigint_undef_signed,col_bigint_undef_signed_not_null,col_float_undef_signed,col_float_undef_signed_not_null,col_double_undef_signed,col_double_undef_signed_not_null,col_decimal
 [...]
+    """
+
+    qt_sql """ select LAST_VALUE(col_tinyint_undef_signed_not_null) over 
(partition by col_double_undef_signed_not_null, col_int_undef_signed, 
(col_float_undef_signed_not_null - col_int_undef_signed), 
round_bankers(col_int_undef_signed) order by pk rows between unbounded 
preceding and 4 preceding) AS col_alias56089 from 
table_200_undef_partitions2_keys3_properties4_distributed_by53 order by 
col_alias56089;  """
 }


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

Reply via email to