/root/doris/be/src/vec/runtime/partitioner.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include "util/runtime_profile.h" |
21 | | #include "vec/exprs/vexpr.h" |
22 | | #include "vec/exprs/vexpr_context.h" |
23 | | |
24 | | namespace doris::vectorized { |
25 | | #include "common/compile_check_begin.h" |
26 | | struct ChannelField { |
27 | | const void* channel_id; |
28 | | const uint32_t len; |
29 | | |
30 | | template <typename T> |
31 | 27 | const T* get() const { |
32 | 27 | CHECK_EQ(sizeof(T), len) << " sizeof(T): " << sizeof(T) << " len: " << len; |
33 | 27 | return reinterpret_cast<const T*>(channel_id); |
34 | 27 | } _ZNK5doris10vectorized12ChannelField3getIjEEPKT_v Line | Count | Source | 31 | 27 | const T* get() const { | 32 | 27 | CHECK_EQ(sizeof(T), len) << " sizeof(T): " << sizeof(T) << " len: " << len; | 33 | 27 | return reinterpret_cast<const T*>(channel_id); | 34 | 27 | } |
Unexecuted instantiation: _ZNK5doris10vectorized12ChannelField3getIlEEPKT_v |
35 | | }; |
36 | | |
37 | | class PartitionerBase { |
38 | | public: |
39 | 20 | PartitionerBase(size_t partition_count) : _partition_count(partition_count) {} |
40 | 20 | virtual ~PartitionerBase() = default; |
41 | | |
42 | | virtual Status init(const std::vector<TExpr>& texprs) = 0; |
43 | | |
44 | | virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc) = 0; |
45 | | |
46 | | virtual Status open(RuntimeState* state) = 0; |
47 | | |
48 | | virtual Status close(RuntimeState* state) = 0; |
49 | | |
50 | | virtual Status do_partitioning(RuntimeState* state, Block* block, bool eos = false, |
51 | | bool* already_sent = nullptr) const = 0; |
52 | | |
53 | | virtual ChannelField get_channel_ids() const = 0; |
54 | | |
55 | | virtual Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) = 0; |
56 | | |
57 | 0 | size_t partition_count() const { return _partition_count; } |
58 | | |
59 | | protected: |
60 | | const size_t _partition_count; |
61 | | }; |
62 | | |
63 | | template <typename ChannelIds> |
64 | | class Crc32HashPartitioner : public PartitionerBase { |
65 | | public: |
66 | 19 | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEEC2Ei Line | Count | Source | 66 | 5 | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} |
_ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEEC2Ei Line | Count | Source | 66 | 14 | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} |
|
67 | 19 | ~Crc32HashPartitioner() override = default; _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEED2Ev Line | Count | Source | 67 | 5 | ~Crc32HashPartitioner() override = default; |
_ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEED2Ev Line | Count | Source | 67 | 14 | ~Crc32HashPartitioner() override = default; |
|
68 | | |
69 | 11 | Status init(const std::vector<TExpr>& texprs) override { |
70 | 11 | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); |
71 | 11 | } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE4initERKSt6vectorINS_5TExprESaIS5_EE _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE4initERKSt6vectorINS_5TExprESaIS5_EE Line | Count | Source | 69 | 11 | Status init(const std::vector<TExpr>& texprs) override { | 70 | 11 | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); | 71 | 11 | } |
|
72 | | |
73 | 9 | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { |
74 | 9 | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); |
75 | 9 | } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE Line | Count | Source | 73 | 9 | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { | 74 | 9 | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); | 75 | 9 | } |
|
76 | | |
77 | 4 | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE4openEPNS_12RuntimeStateE _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE4openEPNS_12RuntimeStateE Line | Count | Source | 77 | 4 | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } |
|
78 | | |
79 | 0 | Status close(RuntimeState* state) override { return Status::OK(); } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE5closeEPNS_12RuntimeStateE Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE5closeEPNS_12RuntimeStateE |
80 | | |
81 | | Status do_partitioning(RuntimeState* state, Block* block, bool eos, |
82 | | bool* already_sent) const override; |
83 | | |
84 | 27 | ChannelField get_channel_ids() const override { return {_hash_vals.data(), sizeof(uint32_t)}; } _ZNK5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE15get_channel_idsEv Line | Count | Source | 84 | 21 | ChannelField get_channel_ids() const override { return {_hash_vals.data(), sizeof(uint32_t)}; } |
_ZNK5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE15get_channel_idsEv Line | Count | Source | 84 | 6 | ChannelField get_channel_ids() const override { return {_hash_vals.data(), sizeof(uint32_t)}; } |
|
85 | | |
86 | | Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) override; |
87 | | |
88 | | protected: |
89 | 27 | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { |
90 | 27 | int counter = 0; |
91 | 27 | for (auto ctx : _partition_expr_ctxs) { |
92 | 27 | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); |
93 | 27 | } |
94 | 27 | return Status::OK(); |
95 | 27 | } _ZNK5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE28_get_partition_column_resultEPNS0_5BlockERSt6vectorIiSaIiEE Line | Count | Source | 89 | 21 | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { | 90 | 21 | int counter = 0; | 91 | 21 | for (auto ctx : _partition_expr_ctxs) { | 92 | 21 | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); | 93 | 21 | } | 94 | 21 | return Status::OK(); | 95 | 21 | } |
_ZNK5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE28_get_partition_column_resultEPNS0_5BlockERSt6vectorIiSaIiEE Line | Count | Source | 89 | 6 | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { | 90 | 6 | int counter = 0; | 91 | 6 | for (auto ctx : _partition_expr_ctxs) { | 92 | 6 | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); | 93 | 6 | } | 94 | 6 | return Status::OK(); | 95 | 6 | } |
|
96 | | |
97 | | void _do_hash(const ColumnPtr& column, uint32_t* __restrict result, int idx) const; |
98 | | |
99 | | VExprContextSPtrs _partition_expr_ctxs; |
100 | | mutable std::vector<uint32_t> _hash_vals; |
101 | | }; |
102 | | |
103 | | struct ShuffleChannelIds { |
104 | | template <typename HashValueType> |
105 | 210 | HashValueType operator()(HashValueType l, size_t r) { |
106 | 210 | return l % r; |
107 | 210 | } |
108 | | }; |
109 | | |
110 | | struct SpillPartitionChannelIds { |
111 | | template <typename HashValueType> |
112 | 3.14M | HashValueType operator()(HashValueType l, size_t r) { |
113 | 3.14M | return ((l >> 16) | (l << 16)) % r; |
114 | 3.14M | } |
115 | | }; |
116 | | #include "common/compile_check_end.h" |
117 | | } // namespace doris::vectorized |