be/src/exprs/function/complex_dict_hash_map.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 "core/column/column.h" |
24 | | #include "core/data_type/data_type.h" |
25 | | #include "core/data_type/data_type_nullable.h" |
26 | | #include "core/data_type/data_type_string.h" |
27 | | #include "exec/common/hash_table/hash.h" |
28 | | #include "exec/common/hash_table/hash_map_context.h" |
29 | | #include "exec/common/hash_table/hash_map_util.h" |
30 | | #include "exec/common/hash_table/ph_hash_map.h" |
31 | | #include "exec/common/hash_table/string_hash_map.h" |
32 | | |
33 | | namespace doris { |
34 | | |
35 | | // key -> column index |
36 | | template <typename KeyType> |
37 | | using DictHashMap = PHHashMap<KeyType, IColumn::ColumnIndex, HashCRC32<KeyType>>; |
38 | | |
39 | | using DictHashMapVariants = std::variant< |
40 | | std::monostate, |
41 | | |
42 | | MethodSerialized<StringHashMap<IColumn::ColumnIndex>>, |
43 | | MethodStringNoCache<StringHashMap<IColumn::ColumnIndex>>, |
44 | | |
45 | | MethodOneNumber<UInt8, DictHashMap<UInt8>>, MethodOneNumber<UInt16, DictHashMap<UInt16>>, |
46 | | MethodOneNumber<UInt32, DictHashMap<UInt32>>, MethodOneNumber<UInt64, DictHashMap<UInt64>>, |
47 | | MethodOneNumber<UInt128, DictHashMap<UInt128>>, |
48 | | MethodOneNumber<UInt256, DictHashMap<UInt256>>, |
49 | | |
50 | | MethodKeysFixed<DictHashMap<UInt64>>, MethodKeysFixed<DictHashMap<UInt72>>, |
51 | | MethodKeysFixed<DictHashMap<UInt96>>, MethodKeysFixed<DictHashMap<UInt104>>, |
52 | | MethodKeysFixed<DictHashMap<UInt128>>, MethodKeysFixed<DictHashMap<UInt136>>, |
53 | | MethodKeysFixed<DictHashMap<UInt256>>>; |
54 | | |
55 | | struct DictionaryHashMapMethod |
56 | | : public DataVariants<DictHashMapVariants, MethodSingleNullableColumn, MethodOneNumber, |
57 | | DataWithNullKey> { |
58 | 1.70k | void init(const std::vector<DataTypePtr>& data_types, HashKeyType type) { |
59 | 1.70k | switch (type) { |
60 | 2 | case HashKeyType::serialized: |
61 | 2 | method_variant.emplace<MethodSerialized<StringHashMap<IColumn::ColumnIndex>>>(); |
62 | 2 | break; |
63 | | // Here we do not call emplace_single because we do not have a corresponding nullable type |
64 | 260 | case HashKeyType::int8_key: |
65 | 260 | method_variant.emplace<MethodOneNumber<UInt8, DictHashMap<UInt8>>>(); |
66 | 260 | break; |
67 | 130 | case HashKeyType::int16_key: |
68 | 130 | method_variant.emplace<MethodOneNumber<UInt16, DictHashMap<UInt16>>>(); |
69 | 130 | break; |
70 | 530 | case HashKeyType::int32_key: |
71 | 530 | method_variant.emplace<MethodOneNumber<UInt32, DictHashMap<UInt32>>>(); |
72 | 530 | break; |
73 | 390 | case HashKeyType::int64_key: |
74 | 390 | method_variant.emplace<MethodOneNumber<UInt64, DictHashMap<UInt64>>>(); |
75 | 390 | break; |
76 | 260 | case HashKeyType::int128_key: |
77 | 260 | method_variant.emplace<MethodOneNumber<UInt128, DictHashMap<UInt128>>>(); |
78 | 260 | break; |
79 | 0 | case HashKeyType::int256_key: |
80 | 0 | method_variant.emplace<MethodOneNumber<UInt256, DictHashMap<UInt256>>>(); |
81 | 0 | break; |
82 | 130 | case HashKeyType::string_key: |
83 | 130 | method_variant.emplace<MethodStringNoCache<StringHashMap<IColumn::ColumnIndex>>>(); |
84 | 130 | break; |
85 | 3 | case HashKeyType::fixed64: |
86 | 3 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt64>>>(get_key_sizes(data_types)); |
87 | 3 | break; |
88 | 0 | case HashKeyType::fixed72: |
89 | 0 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt72>>>(get_key_sizes(data_types)); |
90 | 0 | break; |
91 | 4 | case HashKeyType::fixed96: |
92 | 4 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt96>>>(get_key_sizes(data_types)); |
93 | 4 | break; |
94 | 0 | case HashKeyType::fixed104: |
95 | 0 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt104>>>( |
96 | 0 | get_key_sizes(data_types)); |
97 | 0 | break; |
98 | 0 | case HashKeyType::fixed128: |
99 | 0 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt128>>>( |
100 | 0 | get_key_sizes(data_types)); |
101 | 0 | break; |
102 | 0 | case HashKeyType::fixed136: |
103 | 0 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt136>>>( |
104 | 0 | get_key_sizes(data_types)); |
105 | 0 | break; |
106 | 0 | case HashKeyType::fixed256: |
107 | 0 | method_variant.emplace<MethodKeysFixed<DictHashMap<UInt256>>>( |
108 | 0 | get_key_sizes(data_types)); |
109 | 0 | break; |
110 | 0 | default: |
111 | 0 | throw Exception(ErrorCode::INTERNAL_ERROR, |
112 | 0 | "DictionaryHashMapMethod meet invalid key type, type={}", type); |
113 | 1.70k | } |
114 | 1.70k | } |
115 | | }; |
116 | | |
117 | | } // namespace doris |