be/src/exec/common/set_utils.h
Line | Count | Source |
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 <variant> |
21 | | #include <vector> |
22 | | |
23 | | #include "exec/common/hash_table/hash_map_util.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | struct RowRefWithFlag { |
28 | | bool visited; |
29 | | uint32_t row_num = 0; |
30 | 182 | RowRefWithFlag() = default; |
31 | | #include "common/compile_check_avoid_begin.h" |
32 | | //To consider performance, checks are avoided here. |
33 | | RowRefWithFlag(size_t row_num_count, bool is_visited = false) |
34 | 1.48k | : visited(is_visited), row_num(row_num_count) {} |
35 | | #include "common/compile_check_avoid_end.h" |
36 | | }; |
37 | | |
38 | | template <typename T> |
39 | | using SetData = PHHashMap<T, RowRefWithFlag, HashCRC32<T>>; |
40 | | |
41 | | template <typename T> |
42 | | using SetFixedKeyHashTableContext = MethodKeysFixed<SetData<T>>; |
43 | | |
44 | | template <typename T> |
45 | | using SetPrimaryTypeHashTableContext = MethodOneNumber<T, SetData<T>>; |
46 | | |
47 | | template <typename T> |
48 | | using SetPrimaryTypeHashTableContextNullable = |
49 | | MethodSingleNullableColumn<MethodOneNumber<T, DataWithNullKey<SetData<T>>>>; |
50 | | |
51 | | using SetSerializedHashTableContext = MethodSerialized<PHHashMap<StringRef, RowRefWithFlag>>; |
52 | | using SetMethodOneString = MethodStringNoCache<PHHashMap<StringRef, RowRefWithFlag>>; |
53 | | using SetMethodOneStringNullable = MethodSingleNullableColumn< |
54 | | MethodStringNoCache<DataWithNullKey<PHHashMap<StringRef, RowRefWithFlag>>>>; |
55 | | |
56 | | using SetHashTableVariants = |
57 | | std::variant<std::monostate, SetSerializedHashTableContext, SetMethodOneString, |
58 | | SetMethodOneStringNullable, SetPrimaryTypeHashTableContextNullable<UInt8>, |
59 | | SetPrimaryTypeHashTableContextNullable<UInt16>, |
60 | | SetPrimaryTypeHashTableContextNullable<UInt32>, |
61 | | SetPrimaryTypeHashTableContextNullable<UInt64>, |
62 | | SetPrimaryTypeHashTableContextNullable<UInt128>, |
63 | | SetPrimaryTypeHashTableContextNullable<UInt256>, |
64 | | SetPrimaryTypeHashTableContext<UInt8>, SetPrimaryTypeHashTableContext<UInt16>, |
65 | | SetPrimaryTypeHashTableContext<UInt32>, SetPrimaryTypeHashTableContext<UInt64>, |
66 | | SetPrimaryTypeHashTableContext<UInt128>, |
67 | | SetPrimaryTypeHashTableContext<UInt256>, SetFixedKeyHashTableContext<UInt64>, |
68 | | SetFixedKeyHashTableContext<UInt72>, SetFixedKeyHashTableContext<UInt96>, |
69 | | SetFixedKeyHashTableContext<UInt104>, SetFixedKeyHashTableContext<UInt128>, |
70 | | SetFixedKeyHashTableContext<UInt256>, SetFixedKeyHashTableContext<UInt136>>; |
71 | | |
72 | | struct SetDataVariants : public DataVariants<SetHashTableVariants, MethodSingleNullableColumn, |
73 | | MethodOneNumber, DataWithNullKey> { |
74 | 4.81k | void init(const std::vector<DataTypePtr>& data_types, HashKeyType type) { |
75 | 4.81k | bool nullable = data_types.size() == 1 && data_types[0]->is_nullable(); |
76 | 4.81k | switch (type) { |
77 | 4.47k | case HashKeyType::serialized: |
78 | 4.47k | method_variant.emplace<SetSerializedHashTableContext>(); |
79 | 4.47k | break; |
80 | 19 | case HashKeyType::int8_key: |
81 | 19 | emplace_single<UInt8, SetData<UInt8>>(nullable); |
82 | 19 | break; |
83 | 1 | case HashKeyType::int16_key: |
84 | 1 | emplace_single<UInt16, SetData<UInt16>>(nullable); |
85 | 1 | break; |
86 | 126 | case HashKeyType::int32_key: |
87 | 126 | emplace_single<UInt32, SetData<UInt32>>(nullable); |
88 | 126 | break; |
89 | 17 | case HashKeyType::int64_key: |
90 | 17 | emplace_single<UInt64, SetData<UInt64>>(nullable); |
91 | 17 | break; |
92 | 13 | case HashKeyType::int128_key: |
93 | 13 | emplace_single<UInt128, SetData<UInt128>>(nullable); |
94 | 13 | break; |
95 | 1 | case HashKeyType::int256_key: |
96 | 1 | emplace_single<UInt256, SetData<UInt256>>(nullable); |
97 | 1 | break; |
98 | 126 | case HashKeyType::string_key: |
99 | 126 | if (nullable) { |
100 | 22 | method_variant.emplace<SetMethodOneStringNullable>(); |
101 | 104 | } else { |
102 | 104 | method_variant.emplace<SetMethodOneString>(); |
103 | 104 | } |
104 | 126 | break; |
105 | 11 | case HashKeyType::fixed64: |
106 | 11 | method_variant.emplace<SetFixedKeyHashTableContext<UInt64>>(get_key_sizes(data_types)); |
107 | 11 | break; |
108 | 12 | case HashKeyType::fixed72: |
109 | 12 | method_variant.emplace<SetFixedKeyHashTableContext<UInt72>>(get_key_sizes(data_types)); |
110 | 12 | break; |
111 | 2 | case HashKeyType::fixed96: |
112 | 2 | method_variant.emplace<SetFixedKeyHashTableContext<UInt96>>(get_key_sizes(data_types)); |
113 | 2 | break; |
114 | 15 | case HashKeyType::fixed104: |
115 | 15 | method_variant.emplace<SetFixedKeyHashTableContext<UInt104>>(get_key_sizes(data_types)); |
116 | 15 | break; |
117 | 1 | case HashKeyType::fixed128: |
118 | 1 | method_variant.emplace<SetFixedKeyHashTableContext<UInt128>>(get_key_sizes(data_types)); |
119 | 1 | break; |
120 | 6 | case HashKeyType::fixed136: |
121 | 6 | method_variant.emplace<SetFixedKeyHashTableContext<UInt136>>(get_key_sizes(data_types)); |
122 | 6 | break; |
123 | 3 | case HashKeyType::fixed256: |
124 | 3 | method_variant.emplace<SetFixedKeyHashTableContext<UInt256>>(get_key_sizes(data_types)); |
125 | 3 | break; |
126 | 1 | default: |
127 | 1 | throw Exception(ErrorCode::INTERNAL_ERROR, |
128 | 1 | "SetDataVariants meet invalid key type, type={}", type); |
129 | 4.81k | } |
130 | 4.81k | } |
131 | | }; |
132 | | |
133 | | } // namespace doris |