github-actions[bot] commented on code in PR #39306:
URL: https://github.com/apache/doris/pull/39306#discussion_r1715022410
##########
be/src/vec/common/sort/partition_sorter.cpp:
##########
@@ -67,46 +67,49 @@ Status PartitionSorter::prepare_for_read() {
auto& blocks = _state->get_sorted_block();
auto& priority_queue = _state->get_priority_queue();
for (auto& block : blocks) {
- cursors.emplace_back(block, _sort_description);
+ cursors.emplace_back(MergeSortCursorImpl::create_shared(block,
_sort_description));
}
for (auto& cursor : cursors) {
- priority_queue.push(MergeSortCursor(&cursor));
+ priority_queue.push(std::move(cursor));
}
+ cursors.clear();
return Status::OK();
}
// have done sorter and get topn records, so could reset those state to init
void PartitionSorter::reset_sorter_state(RuntimeState* runtime_state) {
- std::priority_queue<MergeSortBlockCursor> empty_queue;
+ std::priority_queue<std::shared_ptr<MergeSortBlockCursor>> empty_queue;
std::swap(_block_priority_queue, empty_queue);
_state = MergeSorterState::create_unique(_row_desc, _offset, _limit,
runtime_state, nullptr);
_previous_row->reset();
}
Status PartitionSorter::get_next(RuntimeState* state, Block* block, bool* eos)
{
- if (_state->get_sorted_block().empty()) {
+ if (_state->get_sorted_block().empty() &&
_state->get_priority_queue().empty()) {
+ *eos = true;
+ } else if (_state->get_cursors().size() == 1 && _has_global_limit) {
+ auto& cursor = _state->get_cursors()[0];
+ block->swap(*cursor->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:102:** +1, including nesting
penalty of 0, nesting level increased to 1
```cpp
if (priority_queue.empty()) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:114:** +1, including nesting
penalty of 0, nesting level increased to 1
```cpp
while (!priority_queue.empty()) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:117:** +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:121:** +2, including nesting
penalty of 1, nesting level increased to 2
```cpp
switch (_top_n_algorithm) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:124:** +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:125:** +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:128:** +1, nesting level
increased to 3
```cpp
} else {
^
```
**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:140:** +1
```cpp
if (_has_global_limit &&
^
```
**be/src/vec/common/sort/partition_sorter.cpp:145:** +3, including nesting
penalty of 2, nesting level increased to 3
```cpp
if (_has_global_limit) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:147:** +1, nesting level
increased to 3
```cpp
} else {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:150:** +4, including nesting
penalty of 3, nesting level increased to 4
```cpp
if (cmp_res == false) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:152:** +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:159:** +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:169:** +3, including nesting
penalty of 2, nesting level increased to 3
```cpp
if (_has_global_limit &&
^
```
**be/src/vec/common/sort/partition_sorter.cpp:169:** +1
```cpp
if (_has_global_limit &&
^
```
**be/src/vec/common/sort/partition_sorter.cpp:176:** +3, including nesting
penalty of 2, nesting level increased to 3
```cpp
if (cmp_res == false) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:178:** +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:184:** +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:194:** +2, including nesting
penalty of 1, nesting level increased to 2
```cpp
if (!current->is_last()) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:199:** +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:199:** +1
```cpp
if (current_output_rows == batch_size || get_enough_data == true) {
^
```
**be/src/vec/common/sort/partition_sorter.cpp:205:** +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:205:** +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: [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]