@@ -13,6 +13,105 @@ class WriteBuffer;
1313class ReadBuffer ;
1414
1515
16+ template <typename Mapped>
17+ using FindResultImpl = ColumnsHashing::columns_hashing_impl::FindResultImpl<Mapped, true >;
18+
19+ // / Dummy key getter, always find nothing, used for JOIN ON NULL
20+ template <typename Mapped>
21+ class KeyGetterEmpty
22+ {
23+ public:
24+ struct MappedType
25+ {
26+ using mapped_type = Mapped;
27+ };
28+
29+ using FindResult = ColumnsHashing::columns_hashing_impl::FindResultImpl<Mapped>;
30+
31+ KeyGetterEmpty () = default ;
32+
33+ FindResult findKey (MappedType, size_t , const Arena &) { return FindResult (); }
34+ };
35+
36+ template <HashType type, typename Value, typename Mapped>
37+ struct KeyGetterForTypeImpl ;
38+
39+ template <typename Value, typename Mapped>
40+ struct KeyGetterForTypeImpl <HashType::key8, Value, Mapped>
41+ {
42+ using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt8, false , true >;
43+ };
44+
45+ template <typename Value, typename Mapped>
46+ struct KeyGetterForTypeImpl <HashType::key16, Value, Mapped>
47+ {
48+ using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt16, false , true >;
49+ };
50+
51+ template <typename Value, typename Mapped>
52+ struct KeyGetterForTypeImpl <HashType::key32, Value, Mapped>
53+ {
54+ using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt32, false , true >;
55+ };
56+
57+ template <typename Value, typename Mapped>
58+ struct KeyGetterForTypeImpl <HashType::key64, Value, Mapped>
59+ {
60+ using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt64, false , true >;
61+ };
62+
63+ template <typename Value, typename Mapped>
64+ struct KeyGetterForTypeImpl <HashType::key_string, Value, Mapped>
65+ {
66+ using Type = ColumnsHashing::HashMethodString<Value, Mapped, true , false , true >;
67+ };
68+
69+ template <typename Value, typename Mapped>
70+ struct KeyGetterForTypeImpl <HashType::key_fixed_string, Value, Mapped>
71+ {
72+ using Type = ColumnsHashing::HashMethodFixedString<Value, Mapped, true , false , true >;
73+ };
74+
75+ template <typename Value, typename Mapped>
76+ struct KeyGetterForTypeImpl <HashType::keys128, Value, Mapped>
77+ {
78+ using Type = ColumnsHashing::HashMethodKeysFixed<Value, UInt128, Mapped, false , false , false , true >;
79+ };
80+
81+ template <typename Value, typename Mapped>
82+ struct KeyGetterForTypeImpl <HashType::keys256, Value, Mapped>
83+ {
84+ using Type = ColumnsHashing::HashMethodKeysFixed<Value, UInt256, Mapped, false , false , false , true >;
85+ };
86+
87+ template <typename Value, typename Mapped>
88+ struct KeyGetterForTypeImpl <HashType::hashed, Value, Mapped>
89+ {
90+ using Type = ColumnsHashing::HashMethodHashed<Value, Mapped, false , true >;
91+ };
92+
93+ template <HashType type, typename Data>
94+ struct KeyGetterForType
95+ {
96+ using Value = typename Data::value_type;
97+ using Mapped_t = typename Data::mapped_type;
98+ using Mapped = std::conditional_t <std::is_const_v<Data>, const Mapped_t, Mapped_t>;
99+ using Type = typename KeyGetterForTypeImpl<type, Value, Mapped>::Type;
100+ };
101+
102+ template <typename KeyGetter, typename Map, typename MappedHandler>
103+ requires (std::is_invocable_v<MappedHandler, typename Map::mapped_type /* mapped*/ , bool /* inserted*/ , size_t /* row*/ >)
104+ void insertIntoHashMap (
105+ Map & map, const ColumnRawPtrs & key_columns, const Sizes & key_sizes, size_t rows, Arena & pool, MappedHandler && mapped_handler)
106+ {
107+ KeyGetter key_getter (key_columns, key_sizes, nullptr );
108+ for (size_t i = 0 ; i < rows; ++i)
109+ {
110+ auto emplace_result = key_getter.emplaceKey (map, i, pool);
111+ mapped_handler (emplace_result.getMapped (), emplace_result.isInserted (), i);
112+ }
113+ }
114+
16115template <typename Map, typename MappedSerializer>
17116void serializeHashMap (const Map & map, MappedSerializer && mapped_serializer, WriteBuffer & wb)
18117{
@@ -139,6 +238,21 @@ struct HashMapsTemplate
139238 type = which;
140239 }
141240
241+ template <typename MappedHandler>
242+ void insert (const ColumnRawPtrs & key_columns, const Sizes & key_sizes, size_t rows, Arena & pool, MappedHandler && mapped_handler)
243+ {
244+ switch (which)
245+ {
246+ #define M (NAME ) \
247+ case HashType::NAME: \
248+ using KeyGetter = typename KeyGetterForType<HashType::NAME, std::remove_reference_t <decltype (*NAME)>>::Type; \
249+ insertIntoHashMap<KeyGetter>(*NAME, key_columns, key_sizes, rows, pool, std::mode (mapped_handler)); \
250+ break ;
251+ APPLY_FOR_HASH_KEY_VARIANTS (M)
252+ #undef M
253+ }
254+ }
255+
142256 size_t getTotalRowCount () const
143257 {
144258 switch (type)
@@ -219,89 +333,4 @@ struct HashMapsTemplate
219333 HashType type;
220334};
221335
222- template <typename Mapped>
223- using FindResultImpl = ColumnsHashing::columns_hashing_impl::FindResultImpl<Mapped, true >;
224-
225- // / Dummy key getter, always find nothing, used for JOIN ON NULL
226- template <typename Mapped>
227- class KeyGetterEmpty
228- {
229- public:
230- struct MappedType
231- {
232- using mapped_type = Mapped;
233- };
234-
235- using FindResult = ColumnsHashing::columns_hashing_impl::FindResultImpl<Mapped>;
236-
237- KeyGetterEmpty () = default ;
238-
239- FindResult findKey (MappedType, size_t , const Arena &) { return FindResult (); }
240- };
241-
242- template <HashType type, typename Value, typename Mapped>
243- struct KeyGetterForTypeImpl ;
244-
245- template <typename Value, typename Mapped>
246- struct KeyGetterForTypeImpl <HashType::key8, Value, Mapped>
247- {
248- using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt8, false , true >;
249- };
250-
251- template <typename Value, typename Mapped>
252- struct KeyGetterForTypeImpl <HashType::key16, Value, Mapped>
253- {
254- using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt16, false , true >;
255- };
256-
257- template <typename Value, typename Mapped>
258- struct KeyGetterForTypeImpl <HashType::key32, Value, Mapped>
259- {
260- using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt32, false , true >;
261- };
262-
263- template <typename Value, typename Mapped>
264- struct KeyGetterForTypeImpl <HashType::key64, Value, Mapped>
265- {
266- using Type = ColumnsHashing::HashMethodOneNumber<Value, Mapped, UInt64, false , true >;
267- };
268-
269- template <typename Value, typename Mapped>
270- struct KeyGetterForTypeImpl <HashType::key_string, Value, Mapped>
271- {
272- using Type = ColumnsHashing::HashMethodString<Value, Mapped, true , false , true >;
273- };
274-
275- template <typename Value, typename Mapped>
276- struct KeyGetterForTypeImpl <HashType::key_fixed_string, Value, Mapped>
277- {
278- using Type = ColumnsHashing::HashMethodFixedString<Value, Mapped, true , false , true >;
279- };
280-
281- template <typename Value, typename Mapped>
282- struct KeyGetterForTypeImpl <HashType::keys128, Value, Mapped>
283- {
284- using Type = ColumnsHashing::HashMethodKeysFixed<Value, UInt128, Mapped, false , false , false , true >;
285- };
286-
287- template <typename Value, typename Mapped>
288- struct KeyGetterForTypeImpl <HashType::keys256, Value, Mapped>
289- {
290- using Type = ColumnsHashing::HashMethodKeysFixed<Value, UInt256, Mapped, false , false , false , true >;
291- };
292-
293- template <typename Value, typename Mapped>
294- struct KeyGetterForTypeImpl <HashType::hashed, Value, Mapped>
295- {
296- using Type = ColumnsHashing::HashMethodHashed<Value, Mapped, false , true >;
297- };
298-
299- template <HashType type, typename Data>
300- struct KeyGetterForType
301- {
302- using Value = typename Data::value_type;
303- using Mapped_t = typename Data::mapped_type;
304- using Mapped = std::conditional_t <std::is_const_v<Data>, const Mapped_t, Mapped_t>;
305- using Type = typename KeyGetterForTypeImpl<type, Value, Mapped>::Type;
306- };
307336}
0 commit comments