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


##########
be/src/vec/runtime/partitioner.h:
##########
@@ -0,0 +1,94 @@
+// 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 "util/runtime_profile.h"
+#include "vec/exprs/vexpr.h"
+#include "vec/exprs/vexpr_context.h"
+
+namespace doris {
+class MemTracker;
+
+namespace vectorized {
+
+class Partitioner {
+public:
+    Partitioner(int partition_count) : _partition_count(partition_count) {}
+    virtual ~Partitioner() = default;
+
+    Status init(const std::vector<TExpr>& texprs) {
+        return VExpr::create_expr_trees(texprs, _partition_expr_ctxs);
+    }
+
+    Status prepare(RuntimeState* state, const RowDescriptor& row_desc) {
+        return VExpr::prepare(_partition_expr_ctxs, state, row_desc);
+    }
+
+    Status open(RuntimeState* state) { return 
VExpr::open(_partition_expr_ctxs, state); }
+
+    virtual Status do_partitioning(RuntimeState* state, Block* block,
+                                   MemTracker* mem_tracker) const = 0;
+
+    virtual uint8* get_hash_values() const = 0;
+
+protected:
+    Status _get_partition_column_result(Block* block, int* result) const {

Review Comment:
   warning: method '_get_partition_column_result' can be made static 
[readability-convert-member-functions-to-static]
   
   ```suggestion
       static Status _get_partition_column_result(Block* block, int* result) {
   ```
   



##########
be/src/vec/runtime/partitioner.cpp:
##########
@@ -0,0 +1,101 @@
+// 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 "partitioner.h"
+
+#include "runtime/thread_context.h"
+#include "vec/columns/column_const.h"
+
+namespace doris::vectorized {
+
+Status HashPartitioner::do_partitioning(RuntimeState* state, Block* block,
+                                        MemTracker* mem_tracker) const {
+    // will only copy schema
+    // we don't want send temp columns
+    auto column_to_keep = block->columns();
+
+    int result_size = _partition_expr_ctxs.size();
+    int result[result_size];

Review Comment:
   warning: do not declare C VLA arrays, use std::vector<> instead 
[modernize-avoid-c-arrays]
   ```cpp
       int result[result_size];
       ^
   ```
   



##########
be/src/vec/runtime/partitioner.cpp:
##########
@@ -0,0 +1,101 @@
+// 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 "partitioner.h"
+
+#include "runtime/thread_context.h"
+#include "vec/columns/column_const.h"
+
+namespace doris::vectorized {
+
+Status HashPartitioner::do_partitioning(RuntimeState* state, Block* block,
+                                        MemTracker* mem_tracker) const {
+    // will only copy schema
+    // we don't want send temp columns
+    auto column_to_keep = block->columns();
+
+    int result_size = _partition_expr_ctxs.size();
+    int result[result_size];
+
+    // vectorized calculate hash
+    int rows = block->rows();
+    _hash_vals.resize(rows);
+    auto* __restrict hashes = _hash_vals.data();
+
+    if (rows > 0) {
+        {
+            SCOPED_CONSUME_MEM_TRACKER(mem_tracker);
+            RETURN_IF_ERROR(_get_partition_column_result(block, result));
+        }
+        SCOPED_TIMER(*_split_block_hash_compute_timer);
+        // result[j] means column index, i means rows index, here to calculate 
the xxhash value
+        for (int j = 0; j < result_size; ++j) {
+            // complex type most not implement get_data_at() method which 
column_const will call
+            unpack_if_const(block->get_by_position(result[j]).column)
+                    .first->update_hashes_with_value(hashes);
+        }
+
+        for (int i = 0; i < rows; i++) {
+            hashes[i] = hashes[i] % _partition_count;
+        }
+
+        {
+            SCOPED_CONSUME_MEM_TRACKER(mem_tracker);
+            Block::erase_useless_column(block, column_to_keep);
+        }
+    }
+    return Status::OK();
+}
+
+Status BucketHashPartitioner::do_partitioning(RuntimeState* state, Block* 
block,
+                                              MemTracker* mem_tracker) const {
+    // will only copy schema
+    // we don't want send temp columns
+    auto column_to_keep = block->columns();
+
+    int result_size = _partition_expr_ctxs.size();
+    int result[result_size];

Review Comment:
   warning: do not declare C VLA arrays, use std::vector<> instead 
[modernize-avoid-c-arrays]
   ```cpp
       int result[result_size];
       ^
   ```
   



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