github-actions[bot] commented on code in PR #45256: URL: https://github.com/apache/doris/pull/45256#discussion_r1877812252
########## be/src/pipeline/shuffle/writer.cpp: ########## @@ -0,0 +1,114 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "writer.h" + +#include "pipeline/exec/exchange_sink_operator.h" +#include "vec/core/block.h" + +namespace doris::pipeline { +#include "common/compile_check_begin.h" +template <typename ChannelPtrType> +void Writer::_handle_eof_channel(RuntimeState* state, ChannelPtrType channel, Status st) const { + channel->set_receiver_eof(st); + // Chanel will not send RPC to the downstream when eof, so close chanel by OK status. + static_cast<void>(channel->close(state)); +} + +Status Writer::write(ExchangeSinkLocalState* local_state, RuntimeState* state, + vectorized::Block* block, bool eos) const { + auto rows = block->rows(); + { + SCOPED_TIMER(local_state->split_block_hash_compute_timer()); + RETURN_IF_ERROR(local_state->partitioner()->do_partitioning(state, block)); + } + int64_t old_channel_mem_usage = 0; + for (const auto& channel : local_state->channels) { + old_channel_mem_usage += channel->mem_usage(); + } + { + SCOPED_TIMER(local_state->distribute_rows_into_channels_timer()); + const auto& channel_filed = local_state->partitioner()->get_channel_ids(); + if (channel_filed.len == sizeof(uint32_t)) { + RETURN_IF_ERROR(_channel_add_rows(state, local_state->channels, + local_state->partitioner()->partition_count(), + channel_filed.get<uint32_t>(), rows, block, eos)); + } else { + RETURN_IF_ERROR(_channel_add_rows(state, local_state->channels, + local_state->partitioner()->partition_count(), + channel_filed.get<int64_t>(), rows, block, eos)); + } + } + int64_t new_channel_mem_usage = 0; + for (const auto& channel : local_state->channels) { + new_channel_mem_usage += channel->mem_usage(); + } + COUNTER_UPDATE(local_state->memory_used_counter(), + new_channel_mem_usage - old_channel_mem_usage); + return Status::OK(); +} + +template <typename ChannelIdType> +Status Writer::_channel_add_rows(RuntimeState* state, Review Comment: warning: function '_channel_add_rows' has cognitive complexity of 55 (threshold 50) [readability-function-cognitive-complexity] ```cpp Status Writer::_channel_add_rows(RuntimeState* state, ^ ``` <details> <summary>Additional context</summary> **be/src/pipeline/shuffle/writer.cpp:74:** +1, including nesting penalty of 0, nesting level increased to 1 ```cpp for (size_t i = 0; i < rows; ++i) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:77:** +1, including nesting penalty of 0, nesting level increased to 1 ```cpp for (size_t i = 1; i <= partition_count + 1; ++i) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:80:** +1, including nesting penalty of 0, nesting level increased to 1 ```cpp for (int32_t i = cast_set<int32_t>(rows) - 1; i >= 0; --i) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:94:** +1, including nesting penalty of 0, nesting level increased to 1 ```cpp for (size_t i = 0; i < partition_count; ++i) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:97:** +2, including nesting penalty of 1, nesting level increased to 2 ```cpp if (!channels[i]->is_receiver_eof() && size > 0) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:97:** +1 ```cpp if (!channels[i]->is_receiver_eof() && size > 0) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:99:** +3, including nesting penalty of 2, nesting level increased to 3 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:86:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp do { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:99:** +4, including nesting penalty of 3, nesting level increased to 4 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:87:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp if (status.is<ErrorCode::END_OF_FILE>()) { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:99:** +1, nesting level increased to 4 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:89:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp } else { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:99:** +5, including nesting penalty of 4, nesting level increased to 5 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:90:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp RETURN_IF_ERROR(status); \ ^ ``` **be/src/common/status.h:632:** expanded from macro 'RETURN_IF_ERROR' ```cpp do { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:99:** +6, including nesting penalty of 5, nesting level increased to 6 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:90:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp RETURN_IF_ERROR(status); \ ^ ``` **be/src/common/status.h:634:** expanded from macro 'RETURN_IF_ERROR' ```cpp if (UNLIKELY(!_status_.ok())) { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:102:** +1, including nesting penalty of 0, nesting level increased to 1 ```cpp if (eos) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:103:** +2, including nesting penalty of 1, nesting level increased to 2 ```cpp for (int i = 0; i < partition_count; ++i) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:104:** +3, including nesting penalty of 2, nesting level increased to 3 ```cpp if (!channels[i]->is_receiver_eof()) { ^ ``` **be/src/pipeline/shuffle/writer.cpp:106:** +4, including nesting penalty of 3, nesting level increased to 4 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:86:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp do { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:106:** +5, including nesting penalty of 4, nesting level increased to 5 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:87:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp if (status.is<ErrorCode::END_OF_FILE>()) { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:106:** +1, nesting level increased to 5 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:89:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp } else { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:106:** +6, including nesting penalty of 5, nesting level increased to 6 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:90:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp RETURN_IF_ERROR(status); \ ^ ``` **be/src/common/status.h:632:** expanded from macro 'RETURN_IF_ERROR' ```cpp do { \ ^ ``` **be/src/pipeline/shuffle/writer.cpp:106:** +7, including nesting penalty of 6, nesting level increased to 7 ```cpp HANDLE_CHANNEL_STATUS(state, channels[i], status); ^ ``` **be/src/pipeline/shuffle/writer.cpp:90:** expanded from macro 'HANDLE_CHANNEL_STATUS' ```cpp RETURN_IF_ERROR(status); \ ^ ``` **be/src/common/status.h:634:** expanded from macro 'RETURN_IF_ERROR' ```cpp if (UNLIKELY(!_status_.ok())) { \ ^ ``` </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