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


##########
be/src/vec/common/sort/partition_sorter.cpp:
##########
@@ -84,29 +81,30 @@ void PartitionSorter::reset_sorter_state(RuntimeState* 
runtime_state) {
 }
 
 Status PartitionSorter::get_next(RuntimeState* state, Block* block, bool* eos) 
{
-    if (_state->get_sorted_block().empty()) {
+    if (_state->get_priority_queue().empty()) {
+        *eos = true;
+    } else if (_state->get_priority_queue().size() == 1 && _has_global_limit) {
+        block->swap(*_state->get_priority_queue().top().impl->block);
+        block->set_num_rows(_partition_inner_limit);
         *eos = true;
     } else {
-        if (_state->get_sorted_block().size() == 1 && _has_global_limit) {
-            auto& sorted_block = _state->get_sorted_block()[0];
-            block->swap(sorted_block);
-            block->set_num_rows(_partition_inner_limit);
-            *eos = true;
-        } else {
-            RETURN_IF_ERROR(partition_sort_read(block, eos, 
state->batch_size()));
-        }
+        RETURN_IF_ERROR(partition_sort_read(block, eos, state->batch_size()));
     }
     return Status::OK();
 }
 
 Status PartitionSorter::partition_sort_read(Block* output_block, bool* eos, 
int batch_size) {

Review Comment:
   warning: function 'partition_sort_read' has cognitive complexity of 55 
(threshold 50) [readability-function-cognitive-complexity]
   ```cpp
   Status PartitionSorter::partition_sort_read(Block* output_block, bool* eos, 
int batch_size) {
                           ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/common/sort/partition_sorter.cpp:97:** +1, including nesting 
penalty of 0, nesting level increased to 1
   ```cpp
       if (priority_queue.empty()) {
       ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:109:** +1, including nesting 
penalty of 0, nesting level increased to 1
   ```cpp
       while (!priority_queue.empty()) {
       ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:112:** +2, including nesting 
penalty of 1, nesting level increased to 2
   ```cpp
           if (UNLIKELY(_previous_row->impl == nullptr)) {
           ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:116:** +2, including nesting 
penalty of 1, nesting level increased to 2
   ```cpp
           switch (_top_n_algorithm) {
           ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:119:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               if ((current_output_rows + _output_total_rows) < 
_partition_inner_limit) {
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:120:** +4, including nesting 
penalty of 3, nesting level increased to 4
   ```cpp
                   for (size_t i = 0; i < num_columns; ++i) {
                   ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:123:** +1, nesting level 
increased to 3
   ```cpp
               } else {
                 ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:135:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               if (_has_global_limit &&
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:135:** +1
   ```cpp
               if (_has_global_limit &&
                                     ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:140:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               if (_has_global_limit) {
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:142:** +1, nesting level 
increased to 3
   ```cpp
               } else {
                 ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:145:** +4, including nesting 
penalty of 3, nesting level increased to 4
   ```cpp
                   if (cmp_res == false) {
                   ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:147:** +5, including nesting 
penalty of 4, nesting level increased to 5
   ```cpp
                       if (_output_distinct_rows >= _partition_inner_limit) {
                       ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:154:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               for (size_t i = 0; i < num_columns; ++i) {
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:164:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               if (_has_global_limit &&
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:164:** +1
   ```cpp
               if (_has_global_limit &&
                                     ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:171:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               if (cmp_res == false) {
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:173:** +4, including nesting 
penalty of 3, nesting level increased to 4
   ```cpp
                   if ((current_output_rows + _output_total_rows) >= 
_partition_inner_limit) {
                   ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:179:** +3, including nesting 
penalty of 2, nesting level increased to 3
   ```cpp
               for (size_t i = 0; i < num_columns; ++i) {
               ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:189:** +2, including nesting 
penalty of 1, nesting level increased to 2
   ```cpp
           if (!current->is_last()) {
           ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:194:** +2, including nesting 
penalty of 1, nesting level increased to 2
   ```cpp
           if (current_output_rows == batch_size || get_enough_data == true) {
           ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:194:** +1
   ```cpp
           if (current_output_rows == batch_size || get_enough_data == true) {
                                                 ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:200:** +1, including nesting 
penalty of 0, nesting level increased to 1
   ```cpp
       if (current_output_rows == 0 || get_enough_data == true) {
       ^
   ```
   **be/src/vec/common/sort/partition_sorter.cpp:200:** +1
   ```cpp
       if (current_output_rows == 0 || get_enough_data == true) {
                                    ^
   ```
   
   </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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


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

Reply via email to