github-actions[bot] commented on code in PR #39270:
URL: https://github.com/apache/doris/pull/39270#discussion_r1714581071


##########
be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:
##########
@@ -21,26 +21,29 @@
 
 #pragma once
 
-#include <stddef.h>
-#include <stdint.h>
+#include <gen_cpp/data.pb.h>

Review Comment:
   warning: 'gen_cpp/data.pb.h' file not found [clang-diagnostic-error]
   ```cpp
   #include <gen_cpp/data.pb.h>
            ^
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:
##########
@@ -72,16 +75,392 @@
     }
 }
 
-template <typename DateValueType, typename NativeType>
+template <TypeIndex TYPE_INDEX, typename NativeType>
 struct WindowFunnelState {
+    using DateValueType = std::conditional_t<TYPE_INDEX == 
TypeIndex::DateTimeV2,
+                                             DateV2Value<DateTimeV2ValueType>, 
VecDateTimeValue>;
+    int event_count = 0;
+    int64_t window;
+    bool enable_mode;
+    WindowFunnelMode window_funnel_mode;
+    mutable MutableColumnPtr timestamp_column;
+    mutable MutableColumns event_columns;
+    ColumnVector<NativeType>::Container* timestamp_column_data;
+    std::vector<ColumnVector<UInt8>::Container*> event_columns_datas;
+    Block block;
+    SortDescription sort_description {1};
+    bool sorted;
+    bool is_merge;
+
+    WindowFunnelState() {
+        event_count = 0;
+        window = 0;
+        window_funnel_mode = WindowFunnelMode::INVALID;
+
+        sort_description[0].column_number = 0;
+        sort_description[0].direction = 1;
+        sort_description[0].nulls_direction = -1;
+        sorted = false;
+        is_merge = false;
+    }
+    WindowFunnelState(int arg_event_count) : WindowFunnelState() {
+        timestamp_column = ColumnVector<NativeType>::create();
+        timestamp_column_data =
+                
&assert_cast<ColumnVector<NativeType>&>(*timestamp_column).get_data();
+        event_count = arg_event_count;
+        event_columns.resize(event_count);
+        for (int i = 0; i < event_count; i++) {
+            event_columns[i] = ColumnVector<UInt8>::create();
+            event_columns_datas.emplace_back(
+                    
&assert_cast<ColumnVector<UInt8>&>(*event_columns[i]).get_data());
+        }
+    }
+
+    void reset() {
+        window = 0;
+        timestamp_column->clear();
+        for (auto& column : event_columns) {
+            column->clear();
+        }
+        block.clear_column_data();
+        sorted = false;
+        is_merge = false;
+    }
+
+    void add(const IColumn** arg_columns, ssize_t row_num, int64_t win, 
WindowFunnelMode mode) {
+        window = win;
+        window_funnel_mode = enable_mode ? mode : WindowFunnelMode::DEFAULT;
+
+        timestamp_column_data->push_back(
+                assert_cast<const 
ColumnVector<NativeType>&>(*arg_columns[2]).get_data()[row_num]);
+        for (int i = 0; i < event_count; i++) {
+            event_columns_datas[i]->push_back(
+                    assert_cast<const ColumnVector<UInt8>&>(*arg_columns[3 + 
i])
+                            .get_data()[row_num]);
+        }
+    }
+
+    void sort() {
+        if (sorted) {
+            return;
+        }
+        if (!is_merge) {
+            Block tmp_block;
+            tmp_block.insert({std::move(timestamp_column),
+                              
DataTypeFactory::instance().create_data_type(TYPE_INDEX),
+                              "timestamp"});
+            for (int i = 0; i < event_count; i++) {
+                tmp_block.insert({std::move(event_columns[i]),
+                                  
DataTypeFactory::instance().create_data_type(TypeIndex::UInt8),
+                                  "event_" + std::to_string(i)});
+            }
+
+            block = tmp_block.clone_without_columns();
+            sort_block(tmp_block, block, sort_description, 0);
+        } else {
+            auto tmp_block = block.clone_without_columns();
+            sort_block(block, tmp_block, sort_description, 0);
+            block = std::move(tmp_block);
+        }
+        sorted = true;
+    }
+
+    template <WindowFunnelMode WINDOW_FUNNEL_MODE>
+    int _match_event_list(size_t& start_row, size_t row_count,

Review Comment:
   warning: function '_match_event_list' has cognitive complexity of 63 
(threshold 50) [readability-function-cognitive-complexity]
   ```cpp
       int _match_event_list(size_t& start_row, size_t row_count,
           ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:181:** 
+1, including nesting penalty of 0, nesting level increased to 1
   ```cpp
           if (match_row < row_count) {
           ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:190:** 
+2, including nesting penalty of 1, nesting level increased to 2
   ```cpp
               for (; column_idx < event_count + 1; column_idx++) {
               ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:194:** 
+3, including nesting penalty of 2, nesting level increased to 3
   ```cpp
                   if constexpr (WINDOW_FUNNEL_MODE == WindowFunnelMode::FIXED) 
{
                   ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:196:** 
+4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (event_data[match_row] == 1) {
                       ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:199:** 
+5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (current_timestamp <= end_timestamp) {
                           ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:207:** 
+3, including nesting penalty of 2, nesting level increased to 3
   ```cpp
                   if (match_row < row_count) {
                   ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:211:** 
+4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (is_matched) {
                       ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:212:** 
+5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if constexpr (WINDOW_FUNNEL_MODE == 
WindowFunnelMode::INCREASE) {
                           ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:216:** 
+4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if (!is_matched) {
                       ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:219:** 
+4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (WINDOW_FUNNEL_MODE == 
WindowFunnelMode::INCREASE) {
                       ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:223:** 
+4, including nesting penalty of 3, nesting level increased to 4
   ```cpp
                       if constexpr (WINDOW_FUNNEL_MODE == 
WindowFunnelMode::DEDUPLICATION) {
                       ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:225:** 
+5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (match_row != last_match_row + 1) {
                           ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:226:** 
+6, including nesting penalty of 5, nesting level increased to 6
   ```cpp
                               for (int tmp_column_idx = 1; tmp_column_idx < 
column_idx;
                               ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:236:** 
+7, including nesting penalty of 6, nesting level increased to 7
   ```cpp
                                   if (dup_match_row < match_row) {
                                   ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:242:** 
+5, including nesting penalty of 4, nesting level increased to 5
   ```cpp
                           if (is_dup) {
                           ^
   ```
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:248:** 
+1, nesting level increased to 3
   ```cpp
                   } else {
                     ^
   ```
   
   </details>
   



##########
be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:
##########
@@ -72,16 +75,392 @@
     }
 }
 
-template <typename DateValueType, typename NativeType>
+template <TypeIndex TYPE_INDEX, typename NativeType>
 struct WindowFunnelState {
+    using DateValueType = std::conditional_t<TYPE_INDEX == 
TypeIndex::DateTimeV2,
+                                             DateV2Value<DateTimeV2ValueType>, 
VecDateTimeValue>;
+    int event_count = 0;
+    int64_t window;
+    bool enable_mode;
+    WindowFunnelMode window_funnel_mode;
+    mutable MutableColumnPtr timestamp_column;
+    mutable MutableColumns event_columns;
+    ColumnVector<NativeType>::Container* timestamp_column_data;
+    std::vector<ColumnVector<UInt8>::Container*> event_columns_datas;
+    Block block;
+    SortDescription sort_description {1};
+    bool sorted;
+    bool is_merge;
+
+    WindowFunnelState() {
+        event_count = 0;
+        window = 0;
+        window_funnel_mode = WindowFunnelMode::INVALID;
+
+        sort_description[0].column_number = 0;
+        sort_description[0].direction = 1;
+        sort_description[0].nulls_direction = -1;
+        sorted = false;
+        is_merge = false;
+    }
+    WindowFunnelState(int arg_event_count) : WindowFunnelState() {
+        timestamp_column = ColumnVector<NativeType>::create();
+        timestamp_column_data =
+                
&assert_cast<ColumnVector<NativeType>&>(*timestamp_column).get_data();
+        event_count = arg_event_count;
+        event_columns.resize(event_count);
+        for (int i = 0; i < event_count; i++) {
+            event_columns[i] = ColumnVector<UInt8>::create();
+            event_columns_datas.emplace_back(
+                    
&assert_cast<ColumnVector<UInt8>&>(*event_columns[i]).get_data());
+        }
+    }
+
+    void reset() {
+        window = 0;
+        timestamp_column->clear();
+        for (auto& column : event_columns) {
+            column->clear();
+        }
+        block.clear_column_data();
+        sorted = false;
+        is_merge = false;
+    }
+
+    void add(const IColumn** arg_columns, ssize_t row_num, int64_t win, 
WindowFunnelMode mode) {
+        window = win;
+        window_funnel_mode = enable_mode ? mode : WindowFunnelMode::DEFAULT;
+
+        timestamp_column_data->push_back(
+                assert_cast<const 
ColumnVector<NativeType>&>(*arg_columns[2]).get_data()[row_num]);
+        for (int i = 0; i < event_count; i++) {
+            event_columns_datas[i]->push_back(
+                    assert_cast<const ColumnVector<UInt8>&>(*arg_columns[3 + 
i])
+                            .get_data()[row_num]);
+        }
+    }
+
+    void sort() {
+        if (sorted) {
+            return;
+        }
+        if (!is_merge) {
+            Block tmp_block;
+            tmp_block.insert({std::move(timestamp_column),
+                              
DataTypeFactory::instance().create_data_type(TYPE_INDEX),
+                              "timestamp"});
+            for (int i = 0; i < event_count; i++) {
+                tmp_block.insert({std::move(event_columns[i]),
+                                  
DataTypeFactory::instance().create_data_type(TypeIndex::UInt8),
+                                  "event_" + std::to_string(i)});
+            }
+
+            block = tmp_block.clone_without_columns();
+            sort_block(tmp_block, block, sort_description, 0);
+        } else {
+            auto tmp_block = block.clone_without_columns();
+            sort_block(block, tmp_block, sort_description, 0);
+            block = std::move(tmp_block);
+        }
+        sorted = true;
+    }
+
+    template <WindowFunnelMode WINDOW_FUNNEL_MODE>
+    int _match_event_list(size_t& start_row, size_t row_count,

Review Comment:
   warning: function '_match_event_list' exceeds recommended size/complexity 
thresholds [readability-function-size]
   ```cpp
       int _match_event_list(size_t& start_row, size_t row_count,
           ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:168:** 
85 lines including whitespace and comments (threshold 80)
   ```cpp
       int _match_event_list(size_t& start_row, size_t row_count,
           ^
   ```
   
   </details>
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to