/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 { |
25 | | #include "common/compile_check_begin.h" |
26 | | class MemTracker; |
27 | | |
28 | | namespace vectorized { |
29 | | |
30 | | struct ChannelField { |
31 | | const void* channel_id; |
32 | | const uint32_t len; |
33 | | |
34 | | template <typename T> |
35 | 0 | const T* get() const { |
36 | 0 | CHECK_EQ(sizeof(T), len) << " sizeof(T): " << sizeof(T) << " len: " << len; |
37 | 0 | return reinterpret_cast<const T*>(channel_id); |
38 | 0 | } |
39 | | }; |
40 | | |
41 | | class PartitionerBase { |
42 | | public: |
43 | 0 | PartitionerBase(size_t partition_count) : _partition_count(partition_count) {} |
44 | 0 | virtual ~PartitionerBase() = default; |
45 | | |
46 | | virtual Status init(const std::vector<TExpr>& texprs) = 0; |
47 | | |
48 | | virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc) = 0; |
49 | | |
50 | | virtual Status open(RuntimeState* state) = 0; |
51 | | |
52 | | virtual Status do_partitioning(RuntimeState* state, Block* block) const = 0; |
53 | | |
54 | | virtual ChannelField get_channel_ids() const = 0; |
55 | | |
56 | | virtual Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) = 0; |
57 | | |
58 | | protected: |
59 | | const size_t _partition_count; |
60 | | }; |
61 | | |
62 | | template <typename ChannelIds> |
63 | | class Crc32HashPartitioner : public PartitionerBase { |
64 | | public: |
65 | 0 | Crc32HashPartitioner(int partition_count) : PartitionerBase(partition_count) {} Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEEC2Ei Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEEC2Ei |
66 | 0 | ~Crc32HashPartitioner() override = default; Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEED2Ev Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEED2Ev |
67 | | |
68 | 0 | Status init(const std::vector<TExpr>& texprs) override { |
69 | 0 | return VExpr::create_expr_trees(texprs, _partition_expr_ctxs); |
70 | 0 | } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE4initERKSt6vectorINS_5TExprESaIS5_EE Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE4initERKSt6vectorINS_5TExprESaIS5_EE |
71 | | |
72 | 0 | Status prepare(RuntimeState* state, const RowDescriptor& row_desc) override { |
73 | 0 | return VExpr::prepare(_partition_expr_ctxs, state, row_desc); |
74 | 0 | } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE7prepareEPNS_12RuntimeStateERKNS_13RowDescriptorE |
75 | | |
76 | 0 | Status open(RuntimeState* state) override { return VExpr::open(_partition_expr_ctxs, state); } Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE4openEPNS_12RuntimeStateE Unexecuted instantiation: _ZN5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE4openEPNS_12RuntimeStateE |
77 | | |
78 | | Status do_partitioning(RuntimeState* state, Block* block) const override; |
79 | | |
80 | 0 | ChannelField get_channel_ids() const override { return {_hash_vals.data(), sizeof(uint32_t)}; } Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE15get_channel_idsEv Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE15get_channel_idsEv |
81 | | |
82 | | Status clone(RuntimeState* state, std::unique_ptr<PartitionerBase>& partitioner) override; |
83 | | |
84 | | protected: |
85 | 0 | Status _get_partition_column_result(Block* block, std::vector<int>& result) const { |
86 | 0 | int counter = 0; |
87 | 0 | for (auto ctx : _partition_expr_ctxs) { |
88 | 0 | RETURN_IF_ERROR(ctx->execute(block, &result[counter++])); |
89 | 0 | } |
90 | 0 | return Status::OK(); |
91 | 0 | } Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_17ShuffleChannelIdsEE28_get_partition_column_resultEPNS0_5BlockERSt6vectorIiSaIiEE Unexecuted instantiation: _ZNK5doris10vectorized20Crc32HashPartitionerINS0_24SpillPartitionChannelIdsEE28_get_partition_column_resultEPNS0_5BlockERSt6vectorIiSaIiEE |
92 | | |
93 | | void _do_hash(const ColumnPtr& column, uint32_t* __restrict result, int idx) const; |
94 | | |
95 | | VExprContextSPtrs _partition_expr_ctxs; |
96 | | mutable std::vector<uint32_t> _hash_vals; |
97 | | }; |
98 | | |
99 | | struct ShuffleChannelIds { |
100 | | template <typename HashValueType> |
101 | 0 | HashValueType operator()(HashValueType l, size_t r) { |
102 | 0 | return l % r; |
103 | 0 | } |
104 | | }; |
105 | | |
106 | | struct SpillPartitionChannelIds { |
107 | | template <typename HashValueType> |
108 | 0 | HashValueType operator()(HashValueType l, size_t r) { |
109 | 0 | return ((l >> 16) | (l << 16)) % r; |
110 | 0 | } |
111 | | }; |
112 | | |
113 | | } // namespace vectorized |
114 | | } // namespace doris |
115 | | |
116 | | #include "common/compile_check_end.h" |