github-actions[bot] commented on code in PR #25278: URL: https://github.com/apache/doris/pull/25278#discussion_r1365136282
########## be/src/vec/common/hash_table/hash_map.h: ########## @@ -193,10 +195,112 @@ class HashMapTable : public HashTable<Key, Cell, Hash, Grower, Allocator> { bool has_null_key_data() const { return false; } }; +template <typename Key, typename Cell, typename Hash = DefaultHash<Key>, + typename Grower = HashTableGrower<>, typename Allocator = HashTableAllocator> +class JoinHashMapTable : public HashMapTable<Key, Cell, Hash, Grower, Allocator> { +public: + using Self = JoinHashMapTable; + using Base = HashMapTable<Key, Cell, Hash, Grower, Allocator>; + + using key_type = Key; + using value_type = typename Cell::value_type; + using mapped_type = typename Cell::Mapped; + + using LookupResult = typename Base::LookupResult; + + using HashMapTable<Key, Cell, Hash, Grower, Allocator>::HashMapTable; + + static uint32_t calc_bucket_size(size_t num_elem) { + size_t expect_bucket_size = static_cast<size_t>(num_elem) + (num_elem - 1) / 7; Review Comment: warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers] ```cpp size_t expect_bucket_size = static_cast<size_t>(num_elem) + (num_elem - 1) / 7; ^ ``` ########## be/src/vec/common/hash_table/hash_map.h: ########## @@ -193,10 +195,112 @@ bool has_null_key_data() const { return false; } }; +template <typename Key, typename Cell, typename Hash = DefaultHash<Key>, + typename Grower = HashTableGrower<>, typename Allocator = HashTableAllocator> +class JoinHashMapTable : public HashMapTable<Key, Cell, Hash, Grower, Allocator> { +public: + using Self = JoinHashMapTable; + using Base = HashMapTable<Key, Cell, Hash, Grower, Allocator>; + + using key_type = Key; + using value_type = typename Cell::value_type; + using mapped_type = typename Cell::Mapped; + + using LookupResult = typename Base::LookupResult; + + using HashMapTable<Key, Cell, Hash, Grower, Allocator>::HashMapTable; + + static uint32_t calc_bucket_size(size_t num_elem) { + size_t expect_bucket_size = static_cast<size_t>(num_elem) + (num_elem - 1) / 7; + return phmap::priv::NormalizeCapacity(expect_bucket_size) + 1; + } + + void build(const Key* __restrict keys, const size_t* __restrict hash_values, size_t num_elem, int batch_size) { + max_batch_size = batch_size; + bucket_size = calc_bucket_size(num_elem + 1); + first.resize(bucket_size, 0); + next.resize(num_elem); + + build_keys = keys; + for (size_t i = 1; i < num_elem; i++) { + uint32_t bucket_num = hash_values[i] & (bucket_size - 1); + next[i] = first[bucket_num]; + first[bucket_num] = i; + } + } + + auto find_batch(const Key* __restrict keys, const size_t* __restrict hash_values, int probe_idx, + int probe_rows, std::vector<uint32_t>& probe_idxs, + std::vector<int>& build_idxs) { + auto matched_cnt = 0; + const auto batch_size = max_batch_size; + + if (probe_idx == current_probe_idx) { + current_probe_idx = -1; + auto build_idx = current_build_idx; + current_build_idx = 0; + + while (build_idx && LIKELY(matched_cnt < batch_size)) { + if (keys[probe_idx] == build_keys[build_idx]) { + probe_idxs[matched_cnt] = probe_idx; + build_idxs[matched_cnt] = build_idx; + matched_cnt++; + } + build_idx = next[build_idx]; + } + + if (matched_cnt == max_batch_size && build_idx) { + current_probe_idx = probe_idx; + current_build_idx = build_idx; + return std::pair {probe_idx, matched_cnt}; + } + probe_idx++; + } + + while (LIKELY(probe_idx < probe_rows && matched_cnt < batch_size)) { Review Comment: warning: boolean expression can be simplified by DeMorgan's theorem [readability-simplify-boolean-expr] ```cpp while (LIKELY(probe_idx < probe_rows && matched_cnt < batch_size)) { ^ ``` <details> <summary>Additional context</summary> **be/src/common/compiler_util.h:34:** expanded from macro 'LIKELY' ```cpp #define LIKELY(expr) __builtin_expect(!!(expr), 1) ^ ``` </details> -- 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