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


##########
be/src/pipeline/pipeline_x/local_exchange/local_exchange_sink_operator.h:
##########
@@ -0,0 +1,102 @@
+// 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.
+
+#pragma once
+
+#include "pipeline/pipeline_x/dependency.h"
+#include "pipeline/pipeline_x/operator.h"
+
+namespace doris::pipeline {
+
+class LocalExchangeSinkOperatorX;
+class LocalExchangeSinkLocalState final : public 
PipelineXSinkLocalState<LocalExchangeDependency> {
+public:
+    using Base = PipelineXSinkLocalState<LocalExchangeDependency>;
+    ENABLE_FACTORY_CREATOR(LocalExchangeSinkLocalState);
+
+    LocalExchangeSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* 
state)
+            : Base(parent, state) {}
+    ~LocalExchangeSinkLocalState() override = default;
+
+    Status init(RuntimeState* state, LocalSinkStateInfo& info) override;
+
+    Status channel_add_rows(RuntimeState* state, const uint32_t* __restrict 
channel_ids,
+                            vectorized::Block* block);
+
+private:
+    friend class LocalExchangeSinkOperatorX;
+
+    RuntimeProfile::Counter* _compute_hash_value_timer = nullptr;
+    RuntimeProfile::Counter* _distribute_timer = nullptr;
+    std::unique_ptr<vectorized::PartitionerBase> _partitioner;
+    std::vector<std::unique_ptr<vectorized::MutableBlock>> _mutable_block;
+};
+
+// A single 32-bit division on a recent x64 processor has a throughput of one 
instruction every six cycles with a latency of 26 cycles.
+// In contrast, a multiplication has a throughput of one instruction every 
cycle and a latency of 3 cycles.
+// So we prefer to this algorithm instead of modulo.
+// Reference: 
https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
+struct LocalExchangeChannelIds {
+    static constexpr auto SHIFT_BITS = 32;
+    uint32_t operator()(uint32_t l, uint32_t r) {
+        return ((uint64_t)l * (uint64_t)r) >> SHIFT_BITS;
+    }
+};
+
+class LocalExchangeSinkOperatorX final : public 
DataSinkOperatorX<LocalExchangeSinkLocalState> {
+public:
+    using Base = DataSinkOperatorX<LocalExchangeSinkLocalState>;
+    LocalExchangeSinkOperatorX(int sink_id, int num_partitions, const 
std::vector<TExpr>& texprs)
+            : Base(sink_id, -1), _num_partitions(num_partitions), 
_texprs(texprs) {}
+
+    Status init(const TPlanNode& tnode, RuntimeState* state) override {
+        return Status::InternalError("{} should not init with TPlanNode", 
Base::_name);

Review Comment:
   warning: method 'init' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static Status init() override {
   ```
   



##########
be/src/pipeline/pipeline_x/local_exchange/local_exchange_sink_operator.h:
##########
@@ -0,0 +1,102 @@
+// 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.
+
+#pragma once
+
+#include "pipeline/pipeline_x/dependency.h"
+#include "pipeline/pipeline_x/operator.h"
+
+namespace doris::pipeline {
+
+class LocalExchangeSinkOperatorX;
+class LocalExchangeSinkLocalState final : public 
PipelineXSinkLocalState<LocalExchangeDependency> {
+public:
+    using Base = PipelineXSinkLocalState<LocalExchangeDependency>;
+    ENABLE_FACTORY_CREATOR(LocalExchangeSinkLocalState);
+
+    LocalExchangeSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* 
state)
+            : Base(parent, state) {}
+    ~LocalExchangeSinkLocalState() override = default;
+
+    Status init(RuntimeState* state, LocalSinkStateInfo& info) override;
+
+    Status channel_add_rows(RuntimeState* state, const uint32_t* __restrict 
channel_ids,
+                            vectorized::Block* block);
+
+private:
+    friend class LocalExchangeSinkOperatorX;
+
+    RuntimeProfile::Counter* _compute_hash_value_timer = nullptr;
+    RuntimeProfile::Counter* _distribute_timer = nullptr;
+    std::unique_ptr<vectorized::PartitionerBase> _partitioner;
+    std::vector<std::unique_ptr<vectorized::MutableBlock>> _mutable_block;
+};
+
+// A single 32-bit division on a recent x64 processor has a throughput of one 
instruction every six cycles with a latency of 26 cycles.
+// In contrast, a multiplication has a throughput of one instruction every 
cycle and a latency of 3 cycles.

Review Comment:
   warning: 32 is a magic number; consider replacing it with a named constant 
[readability-magic-numbers]
   ```cpp
       uint32_t operator()(uint32_t l, uint32_t r) { return ((uint64_t)l * 
(uint64_t)r) >> 32; }
                                                                                
           ^
   ```
   



##########
be/src/pipeline/pipeline_x/local_exchange/local_exchange_source_operator.cpp:
##########
@@ -0,0 +1,52 @@
+// 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 "pipeline/pipeline_x/local_exchange/local_exchange_source_operator.h"
+
+namespace doris::pipeline {
+
+Status LocalExchangeSourceLocalState::init(RuntimeState* state, 
LocalStateInfo& info) {
+    RETURN_IF_ERROR(Base::init(state, info));
+    SCOPED_TIMER(profile()->total_time_counter());
+    SCOPED_TIMER(_open_timer);
+    _dependency->set_shared_state(info.local_exchange_state);
+    _shared_state = (LocalExchangeSharedState*)_dependency->shared_state();
+    DCHECK(_shared_state != nullptr);
+    _channel_id = info.task_idx;
+    _dependency->set_channel_id(_channel_id);
+    _get_block_failed_counter =
+            ADD_COUNTER_WITH_LEVEL(profile(), "GetBlockFailedTime", 
TUnit::UNIT, 1);
+    return Status::OK();
+}
+
+Status LocalExchangeSourceOperatorX::get_block(RuntimeState* state, 
vectorized::Block* block,

Review Comment:
   warning: method 'get_block' can be made static 
[readability-convert-member-functions-to-static]
   
   
be/src/pipeline/pipeline_x/local_exchange/local_exchange_source_operator.h:57:
   ```diff
   -     Status get_block(RuntimeState* state, vectorized::Block* block,
   +     static Status get_block(RuntimeState* state, vectorized::Block* block,
   ```
   



##########
be/src/pipeline/pipeline_x/local_exchange/local_exchange_sink_operator.h:
##########
@@ -0,0 +1,102 @@
+// 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.
+
+#pragma once
+
+#include "pipeline/pipeline_x/dependency.h"
+#include "pipeline/pipeline_x/operator.h"
+
+namespace doris::pipeline {
+
+class LocalExchangeSinkOperatorX;
+class LocalExchangeSinkLocalState final : public 
PipelineXSinkLocalState<LocalExchangeDependency> {
+public:
+    using Base = PipelineXSinkLocalState<LocalExchangeDependency>;
+    ENABLE_FACTORY_CREATOR(LocalExchangeSinkLocalState);
+
+    LocalExchangeSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* 
state)
+            : Base(parent, state) {}
+    ~LocalExchangeSinkLocalState() override = default;
+
+    Status init(RuntimeState* state, LocalSinkStateInfo& info) override;
+
+    Status channel_add_rows(RuntimeState* state, const uint32_t* __restrict 
channel_ids,
+                            vectorized::Block* block);
+
+private:
+    friend class LocalExchangeSinkOperatorX;
+
+    RuntimeProfile::Counter* _compute_hash_value_timer = nullptr;
+    RuntimeProfile::Counter* _distribute_timer = nullptr;
+    std::unique_ptr<vectorized::PartitionerBase> _partitioner;
+    std::vector<std::unique_ptr<vectorized::MutableBlock>> _mutable_block;
+};
+
+// A single 32-bit division on a recent x64 processor has a throughput of one 
instruction every six cycles with a latency of 26 cycles.
+// In contrast, a multiplication has a throughput of one instruction every 
cycle and a latency of 3 cycles.
+// So we prefer to this algorithm instead of modulo.
+// Reference: 
https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
+struct LocalExchangeChannelIds {
+    static constexpr auto SHIFT_BITS = 32;
+    uint32_t operator()(uint32_t l, uint32_t r) {
+        return ((uint64_t)l * (uint64_t)r) >> SHIFT_BITS;
+    }
+};
+
+class LocalExchangeSinkOperatorX final : public 
DataSinkOperatorX<LocalExchangeSinkLocalState> {
+public:
+    using Base = DataSinkOperatorX<LocalExchangeSinkLocalState>;
+    LocalExchangeSinkOperatorX(int sink_id, int num_partitions, const 
std::vector<TExpr>& texprs)
+            : Base(sink_id, -1), _num_partitions(num_partitions), 
_texprs(texprs) {}
+
+    Status init(const TPlanNode& tnode, RuntimeState* state) override {
+        return Status::InternalError("{} should not init with TPlanNode", 
Base::_name);
+    }
+
+    Status init(const TDataSink& tsink) override {
+        return Status::InternalError("{} should not init with TPlanNode", 
Base::_name);
+    }
+
+    Status init() override {
+        _name = "LOCAL_EXCHANGE_SINK_OPERATOR";

Review Comment:
   warning: method 'prepare' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static Status prepare(RuntimeState* state) override {
   ```
   



##########
be/src/pipeline/pipeline_x/local_exchange/local_exchange_sink_operator.h:
##########
@@ -0,0 +1,102 @@
+// 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.
+
+#pragma once
+
+#include "pipeline/pipeline_x/dependency.h"
+#include "pipeline/pipeline_x/operator.h"
+
+namespace doris::pipeline {
+
+class LocalExchangeSinkOperatorX;
+class LocalExchangeSinkLocalState final : public 
PipelineXSinkLocalState<LocalExchangeDependency> {
+public:
+    using Base = PipelineXSinkLocalState<LocalExchangeDependency>;
+    ENABLE_FACTORY_CREATOR(LocalExchangeSinkLocalState);
+
+    LocalExchangeSinkLocalState(DataSinkOperatorXBase* parent, RuntimeState* 
state)
+            : Base(parent, state) {}
+    ~LocalExchangeSinkLocalState() override = default;
+
+    Status init(RuntimeState* state, LocalSinkStateInfo& info) override;
+
+    Status channel_add_rows(RuntimeState* state, const uint32_t* __restrict 
channel_ids,
+                            vectorized::Block* block);
+
+private:
+    friend class LocalExchangeSinkOperatorX;
+
+    RuntimeProfile::Counter* _compute_hash_value_timer = nullptr;
+    RuntimeProfile::Counter* _distribute_timer = nullptr;
+    std::unique_ptr<vectorized::PartitionerBase> _partitioner;
+    std::vector<std::unique_ptr<vectorized::MutableBlock>> _mutable_block;
+};
+
+// A single 32-bit division on a recent x64 processor has a throughput of one 
instruction every six cycles with a latency of 26 cycles.
+// In contrast, a multiplication has a throughput of one instruction every 
cycle and a latency of 3 cycles.
+// So we prefer to this algorithm instead of modulo.
+// Reference: 
https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
+struct LocalExchangeChannelIds {
+    static constexpr auto SHIFT_BITS = 32;
+    uint32_t operator()(uint32_t l, uint32_t r) {
+        return ((uint64_t)l * (uint64_t)r) >> SHIFT_BITS;
+    }
+};
+
+class LocalExchangeSinkOperatorX final : public 
DataSinkOperatorX<LocalExchangeSinkLocalState> {
+public:
+    using Base = DataSinkOperatorX<LocalExchangeSinkLocalState>;
+    LocalExchangeSinkOperatorX(int sink_id, int num_partitions, const 
std::vector<TExpr>& texprs)
+            : Base(sink_id, -1), _num_partitions(num_partitions), 
_texprs(texprs) {}
+
+    Status init(const TPlanNode& tnode, RuntimeState* state) override {
+        return Status::InternalError("{} should not init with TPlanNode", 
Base::_name);
+    }
+
+    Status init(const TDataSink& tsink) override {
+        return Status::InternalError("{} should not init with TPlanNode", 
Base::_name);
+    }
+
+    Status init() override {
+        _name = "LOCAL_EXCHANGE_SINK_OPERATOR";
+        _partitioner.reset(
+                new 
vectorized::Crc32HashPartitioner<LocalExchangeChannelIds>(_num_partitions));
+        RETURN_IF_ERROR(_partitioner->init(_texprs));
+        return Status::OK();
+    }

Review Comment:
   warning: method 'open' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static Status open(RuntimeState* state) override {
   ```
   



-- 
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