diff --git a/be/src/exprs/hybrid_set.h b/be/src/exprs/hybrid_set.h index 67c8f43099..54a30cd343 100644 --- a/be/src/exprs/hybrid_set.h +++ b/be/src/exprs/hybrid_set.h @@ -17,14 +17,13 @@ #pragma once -#include - #include "common/object_pool.h" #include "runtime/decimalv2_value.h" #include "runtime/define_primitive_type.h" #include "runtime/primitive_type.h" #include "vec/columns/column_nullable.h" #include "vec/columns/column_string.h" +#include "vec/common/hash_table/phmap_fwd_decl.h" #include "vec/common/string_ref.h" namespace doris { @@ -149,7 +148,7 @@ template class DynamicContainer { public: using Self = DynamicContainer; - using Iterator = typename phmap::flat_hash_set::iterator; + using Iterator = typename vectorized::flat_hash_set::iterator; using ElementType = T; DynamicContainer() = default; @@ -168,7 +167,7 @@ public: size_t size() const { return _set.size(); } private: - phmap::flat_hash_set _set; + vectorized::flat_hash_set _set; }; // TODO Maybe change void* parameter to template parameter better. diff --git a/be/src/olap/hll.cpp b/be/src/olap/hll.cpp index 7c234d1703..8f7a61e712 100644 --- a/be/src/olap/hll.cpp +++ b/be/src/olap/hll.cpp @@ -49,7 +49,7 @@ void HyperLogLog::_convert_explicit_to_register() { _update_registers(value); } // clear _hash_set - phmap::flat_hash_set().swap(_hash_set); + vectorized::flat_hash_set().swap(_hash_set); } // Change HLL_DATA_EXPLICIT to HLL_DATA_FULL directly, because HLL_DATA_SPARSE diff --git a/be/src/olap/hll.h b/be/src/olap/hll.h index a3347f4626..f1ad81100b 100644 --- a/be/src/olap/hll.h +++ b/be/src/olap/hll.h @@ -18,7 +18,6 @@ #pragma once #include -#include #include #include @@ -30,6 +29,7 @@ #endif #include "gutil/macros.h" +#include "vec/common/hash_table/phmap_fwd_decl.h" namespace doris { @@ -268,7 +268,7 @@ public: private: HllDataType _type = HLL_DATA_EMPTY; - phmap::flat_hash_set _hash_set; + vectorized::flat_hash_set _hash_set; // This field is much space consuming(HLL_REGISTERS_COUNT), we create // it only when it is really needed. diff --git a/be/src/olap/in_list_predicate.h b/be/src/olap/in_list_predicate.h index 7d0001cf1c..e207bf28d5 100644 --- a/be/src/olap/in_list_predicate.h +++ b/be/src/olap/in_list_predicate.h @@ -17,8 +17,6 @@ #pragma once -#include - #include #include diff --git a/be/src/olap/reader.cpp b/be/src/olap/reader.cpp index f3ffd44d32..b21691af2d 100644 --- a/be/src/olap/reader.cpp +++ b/be/src/olap/reader.cpp @@ -17,8 +17,6 @@ #include "olap/reader.h" -#include - #include "common/status.h" #include "exprs/create_predicate_function.h" #include "exprs/hybrid_set.h" diff --git a/be/src/olap/rowset/segment_v2/binary_dict_page.h b/be/src/olap/rowset/segment_v2/binary_dict_page.h index 26bf127a1f..b570b042dc 100644 --- a/be/src/olap/rowset/segment_v2/binary_dict_page.h +++ b/be/src/olap/rowset/segment_v2/binary_dict_page.h @@ -17,8 +17,6 @@ #pragma once -#include - #include #include #include diff --git a/be/src/vec/aggregate_functions/aggregate_function.h b/be/src/vec/aggregate_functions/aggregate_function.h index c55612ec15..2d6b07e403 100644 --- a/be/src/vec/aggregate_functions/aggregate_function.h +++ b/be/src/vec/aggregate_functions/aggregate_function.h @@ -20,9 +20,8 @@ #pragma once -#include - #include "vec/columns/column_complex.h" +#include "vec/common/hash_table/phmap_fwd_decl.h" #include "vec/core/block.h" #include "vec/core/column_numbers.h" #include "vec/core/field.h" @@ -221,7 +220,7 @@ public: std::is_same_v>) { if (agg_many) { - phmap::flat_hash_map> place_rows; + flat_hash_map> place_rows; for (int i = 0; i < batch_size; ++i) { auto iter = place_rows.find(places[i] + place_offset); if (iter == place_rows.end()) { diff --git a/be/src/vec/aggregate_functions/aggregate_function_topn.h b/be/src/vec/aggregate_functions/aggregate_function_topn.h index 99ec3dadd9..7bfacf7977 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_topn.h +++ b/be/src/vec/aggregate_functions/aggregate_function_topn.h @@ -17,7 +17,6 @@ #pragma once -#include #include #include @@ -29,6 +28,7 @@ #include "vec/columns/column_array.h" #include "vec/columns/column_string.h" #include "vec/columns/column_vector.h" +#include "vec/common/hash_table/phmap_fwd_decl.h" #include "vec/core/types.h" #include "vec/data_types/data_type_array.h" #include "vec/data_types/data_type_string.h" @@ -183,7 +183,7 @@ struct AggregateFunctionTopNData { int top_num = 0; uint64_t capacity = 0; - phmap::flat_hash_map counter_map; + flat_hash_map counter_map; }; struct AggregateFunctionTopNImplInt { diff --git a/be/src/vec/aggregate_functions/aggregate_function_uniq.h b/be/src/vec/aggregate_functions/aggregate_function_uniq.h index ff17082752..592cb5a925 100644 --- a/be/src/vec/aggregate_functions/aggregate_function_uniq.h +++ b/be/src/vec/aggregate_functions/aggregate_function_uniq.h @@ -20,8 +20,6 @@ #pragma once -#include - #include #include "gutil/hash/city.h" @@ -31,6 +29,7 @@ #include "vec/common/assert_cast.h" #include "vec/common/bit_cast.h" #include "vec/common/hash_table/hash_set.h" +#include "vec/common/hash_table/phmap_fwd_decl.h" #include "vec/common/typeid_cast.h" #include "vec/data_types/data_type_number.h" @@ -47,7 +46,7 @@ struct AggregateFunctionUniqExactData { using Key = std::conditional_t; using Hash = std::conditional_t>; - using Set = phmap::flat_hash_set; + using Set = flat_hash_set; static UInt128 ALWAYS_INLINE get_key(const StringRef& value) { UInt128 key; diff --git a/be/src/vec/common/hash_table/ph_hash_map.h b/be/src/vec/common/hash_table/ph_hash_map.h index 2a847eda75..da51f31cf9 100644 --- a/be/src/vec/common/hash_table/ph_hash_map.h +++ b/be/src/vec/common/hash_table/ph_hash_map.h @@ -23,6 +23,7 @@ #include "vec/common/hash_table/hash.h" #include "vec/common/hash_table/hash_table_utils.h" +#include "vec/common/hash_table/phmap_fwd_decl.h" template ALWAYS_INLINE inline auto lookup_result_get_mapped(std::pair* it) { @@ -36,7 +37,7 @@ public: using Self = PHHashMap; using Hash = HashMethod; using cell_type = std::pair; - using HashMapImpl = phmap::flat_hash_map; + using HashMapImpl = doris::vectorized::flat_hash_map; using key_type = Key; using mapped_type = Mapped; diff --git a/be/src/vec/common/hash_table/phmap_fwd_decl.h b/be/src/vec/common/hash_table/phmap_fwd_decl.h new file mode 100644 index 0000000000..d37eb898e1 --- /dev/null +++ b/be/src/vec/common/hash_table/phmap_fwd_decl.h @@ -0,0 +1,54 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include + +#include "vec/common/allocator.h" + +namespace doris::vectorized { + +/// `Allocator_` implements several interfaces of `std::allocator` +/// which `phmap::flat_hash_map` will use. +template +class Allocator_ : private Allocator { +public: + using value_type = T; + using pointer = T*; + + Allocator_() = default; + + template + Allocator_(const Allocator_&) {}; + + constexpr T* allocate(size_t n) { return static_cast(Allocator::alloc(n * sizeof(T))); } + + void deallocate(pointer p, size_t n) { Allocator::free(p, n * sizeof(T)); } + + friend bool operator==(const Allocator_&, const Allocator_&) { return true; } +}; + +template , typename Eq = phmap::EqualTo, + typename Alloc = Allocator_>> +using flat_hash_map = phmap::flat_hash_map; + +template , typename Eq = phmap::EqualTo, + typename Alloc = Allocator_> +using flat_hash_set = phmap::flat_hash_set; + +} // namespace doris::vectorized