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


##########
be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:
##########
@@ -72,16 +75,367 @@
     }
 }
 
-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 vectorized::MutableBlock mutable_block;
+    ColumnVector<NativeType>::Container* timestamp_column_data;
+    std::vector<ColumnVector<UInt8>::Container*> event_columns_datas;
+    SortDescription sort_description {1};
+    bool sorted;
+
+    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;
+    }
+    WindowFunnelState(int arg_event_count) : WindowFunnelState() {
+        event_count = arg_event_count;
+        auto timestamp_column = ColumnVector<NativeType>::create();
+        timestamp_column_data =
+                
&assert_cast<ColumnVector<NativeType>&>(*timestamp_column).get_data();
+
+        MutableColumns event_columns;
+        for (int i = 0; i < event_count; i++) {
+            auto event_column = ColumnVector<UInt8>::create();
+            event_columns_datas.emplace_back(
+                    
&assert_cast<ColumnVector<UInt8>&>(*event_column).get_data());
+            event_columns.emplace_back(std::move(event_column));
+        }
+        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)});
+        }
+
+        mutable_block = MutableBlock(std::move(tmp_block));
+    }
+
+    void reset() {
+        window = 0;
+        mutable_block.clear();
+        timestamp_column_data = nullptr;
+        event_columns_datas.clear();
+        sorted = 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;
+        }
+
+        Block tmp_block = mutable_block.to_block();
+        auto block = tmp_block.clone_without_columns();
+        sort_block(tmp_block, block, sort_description, 0);
+        mutable_block = MutableBlock(std::move(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:160:** 
84 lines including whitespace and comments (threshold 80)
   ```cpp
       int _match_event_list(size_t& start_row, size_t row_count,
           ^
   ```
   
   </details>
   



##########
be/src/vec/aggregate_functions/aggregate_function_window_funnel.h:
##########
@@ -72,16 +75,367 @@ WindowFunnelMode string_to_window_funnel_mode(const 
String& string) {
     }
 }
 
-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 vectorized::MutableBlock mutable_block;
+    ColumnVector<NativeType>::Container* timestamp_column_data;
+    std::vector<ColumnVector<UInt8>::Container*> event_columns_datas;
+    SortDescription sort_description {1};
+    bool sorted;
+
+    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;
+    }
+    WindowFunnelState(int arg_event_count) : WindowFunnelState() {
+        event_count = arg_event_count;
+        auto timestamp_column = ColumnVector<NativeType>::create();
+        timestamp_column_data =
+                
&assert_cast<ColumnVector<NativeType>&>(*timestamp_column).get_data();
+
+        MutableColumns event_columns;
+        for (int i = 0; i < event_count; i++) {
+            auto event_column = ColumnVector<UInt8>::create();
+            event_columns_datas.emplace_back(
+                    
&assert_cast<ColumnVector<UInt8>&>(*event_column).get_data());
+            event_columns.emplace_back(std::move(event_column));
+        }
+        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)});
+        }
+
+        mutable_block = MutableBlock(std::move(tmp_block));
+    }
+
+    void reset() {
+        window = 0;
+        mutable_block.clear();
+        timestamp_column_data = nullptr;
+        event_columns_datas.clear();
+        sorted = 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;
+        }
+
+        Block tmp_block = mutable_block.to_block();
+        auto block = tmp_block.clone_without_columns();
+        sort_block(tmp_block, block, sort_description, 0);
+        mutable_block = MutableBlock(std::move(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:173:** 
+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:182:** 
+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:186:** 
+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:188:** 
+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:191:** 
+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:199:** 
+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:203:** 
+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:204:** 
+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:208:** 
+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:211:** 
+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:215:** 
+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:217:** 
+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:218:** 
+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:227:** 
+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:233:** 
+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:239:** 
+1, nesting level increased to 3
   ```cpp
                   } else {
                     ^
   ```
   
   </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