yiguolei commented on code in PR #14383: URL: https://github.com/apache/doris/pull/14383#discussion_r1025945190
########## be/src/vec/runtime/shared_hash_table_controller.h: ########## @@ -37,33 +38,170 @@ namespace vectorized { class VExprContext; +template <typename RowRefListType> +struct SerializedHashTableContext { + using Mapped = RowRefListType; + using HashTable = HashMap<StringRef, Mapped>; + using HashTablePtr = std::shared_ptr<HashMap<StringRef, Mapped>>; + using State = ColumnsHashing::HashMethodSerialized<typename HashTable::value_type, Mapped>; + using Iter = typename HashTable::iterator; + + HashTable hash_table; + Iter iter; + bool inited = false; + + void init_once() { + if (!inited) { + inited = true; + iter = hash_table.begin(); + } + } +}; + +template <typename HashMethod> +struct IsSerializedHashTableContextTraits { + constexpr static bool value = false; +}; + +template <typename Value, typename Mapped> +struct IsSerializedHashTableContextTraits<ColumnsHashing::HashMethodSerialized<Value, Mapped>> { + constexpr static bool value = true; +}; + +// T should be UInt32 UInt64 UInt128 +template <class T, typename RowRefListType> +struct PrimaryTypeHashTableContext { + using Mapped = RowRefListType; + using HashTable = HashMap<T, Mapped, HashCRC32<T>>; + using HashTablePtr = std::shared_ptr<HashMap<T, Mapped, HashCRC32<T>>>; + using State = + ColumnsHashing::HashMethodOneNumber<typename HashTable::value_type, Mapped, T, false>; + using Iter = typename HashTable::iterator; + + HashTable hash_table; + Iter iter; + bool inited = false; + + void init_once() { + if (!inited) { + inited = true; + iter = hash_table.begin(); + } + } +}; + +// TODO: use FixedHashTable instead of HashTable +template <typename RowRefListType> +using I8HashTableContext = PrimaryTypeHashTableContext<UInt8, RowRefListType>; +template <typename RowRefListType> +using I16HashTableContext = PrimaryTypeHashTableContext<UInt16, RowRefListType>; +template <typename RowRefListType> +using I32HashTableContext = PrimaryTypeHashTableContext<UInt32, RowRefListType>; +template <typename RowRefListType> +using I64HashTableContext = PrimaryTypeHashTableContext<UInt64, RowRefListType>; +template <typename RowRefListType> +using I128HashTableContext = PrimaryTypeHashTableContext<UInt128, RowRefListType>; +template <typename RowRefListType> +using I256HashTableContext = PrimaryTypeHashTableContext<UInt256, RowRefListType>; + +template <class T, bool has_null, typename RowRefListType> +struct FixedKeyHashTableContext { + using Mapped = RowRefListType; + using HashTable = HashMap<T, Mapped, HashCRC32<T>>; + using HashTablePtr = std::shared_ptr<HashMap<T, Mapped, HashCRC32<T>>>; + using State = ColumnsHashing::HashMethodKeysFixed<typename HashTable::value_type, T, Mapped, + has_null, false>; + using Iter = typename HashTable::iterator; + + HashTable hash_table; + Iter iter; + bool inited = false; + + void init_once() { + if (!inited) { + inited = true; + iter = hash_table.begin(); + } + } +}; + +template <bool has_null, typename RowRefListType> +using I64FixedKeyHashTableContext = FixedKeyHashTableContext<UInt64, has_null, RowRefListType>; + +template <bool has_null, typename RowRefListType> +using I128FixedKeyHashTableContext = FixedKeyHashTableContext<UInt128, has_null, RowRefListType>; + +template <bool has_null, typename RowRefListType> +using I256FixedKeyHashTableContext = FixedKeyHashTableContext<UInt256, has_null, RowRefListType>; + +using HashTableVariants = std::variant< + std::monostate, SerializedHashTableContext<RowRefList>, I8HashTableContext<RowRefList>, + I16HashTableContext<RowRefList>, I32HashTableContext<RowRefList>, + I64HashTableContext<RowRefList>, I128HashTableContext<RowRefList>, + I256HashTableContext<RowRefList>, I64FixedKeyHashTableContext<true, RowRefList>, + I64FixedKeyHashTableContext<false, RowRefList>, + I128FixedKeyHashTableContext<true, RowRefList>, + I128FixedKeyHashTableContext<false, RowRefList>, + I256FixedKeyHashTableContext<true, RowRefList>, + I256FixedKeyHashTableContext<false, RowRefList>, + SerializedHashTableContext<RowRefListWithFlag>, I8HashTableContext<RowRefListWithFlag>, + I16HashTableContext<RowRefListWithFlag>, I32HashTableContext<RowRefListWithFlag>, + I64HashTableContext<RowRefListWithFlag>, I128HashTableContext<RowRefListWithFlag>, + I256HashTableContext<RowRefListWithFlag>, + I64FixedKeyHashTableContext<true, RowRefListWithFlag>, + I64FixedKeyHashTableContext<false, RowRefListWithFlag>, + I128FixedKeyHashTableContext<true, RowRefListWithFlag>, + I128FixedKeyHashTableContext<false, RowRefListWithFlag>, + I256FixedKeyHashTableContext<true, RowRefListWithFlag>, + I256FixedKeyHashTableContext<false, RowRefListWithFlag>, + SerializedHashTableContext<RowRefListWithFlags>, I8HashTableContext<RowRefListWithFlags>, + I16HashTableContext<RowRefListWithFlags>, I32HashTableContext<RowRefListWithFlags>, + I64HashTableContext<RowRefListWithFlags>, I128HashTableContext<RowRefListWithFlags>, + I256HashTableContext<RowRefListWithFlags>, + I64FixedKeyHashTableContext<true, RowRefListWithFlags>, + I64FixedKeyHashTableContext<false, RowRefListWithFlags>, + I128FixedKeyHashTableContext<true, RowRefListWithFlags>, + I128FixedKeyHashTableContext<false, RowRefListWithFlags>, + I256FixedKeyHashTableContext<true, RowRefListWithFlags>, + I256FixedKeyHashTableContext<false, RowRefListWithFlags>>; + +using HashTableVariantsPtr = std::shared_ptr<HashTableVariants>; Review Comment: HashTableVariantsSPtr to indicate it is a shared ptr -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org