You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "HappenLee (via GitHub)" <gi...@apache.org> on 2023/10/11 02:31:22 UTC

[PR] save code [doris]

HappenLee opened a new pull request, #25278:
URL: https://github.com/apache/doris/pull/25278

   ## Proposed changes
   
   Issue Number: close #xxx
   
   <!--Describe your changes.-->
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
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-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] save code [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #25278:
URL: https://github.com/apache/doris/pull/25278#discussion_r1353894018


##########
be/src/vec/exec/join/join_op.h:
##########
@@ -109,21 +111,17 @@ class ForwardIterator {
             return;
         }
 
-        if (batch) {
+        if (batch && position < batch->size()) {
             ++position;
-            if (position >= batch->size) {
-                batch = batch->next;
-                position = 0;
-            }
         }
     }
 
-    bool ok() const { return first || batch; }
+    bool ok() const { return first || (batch && position < batch->size()); }

Review Comment:
   warning: function 'ok' should be marked [[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] bool ok() const { return first || (batch && position < batch->size()); }
   ```
   



-- 
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-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] save code [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
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-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] save code [doris]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on code in PR #25278:
URL: https://github.com/apache/doris/pull/25278#discussion_r1357640403


##########
be/src/vec/common/hash_table/hash_map_context.h:
##########
@@ -126,6 +126,10 @@ struct MethodBase {
         }
     }
 
+    std::span<Key> get_keys() const { return {keys, hash_values.size()}; }
+
+    const size_t* get_hash_values() const { return hash_values.data(); }

Review Comment:
   warning: function 'get_hash_values' should be marked [[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] const size_t* get_hash_values() const { return hash_values.data(); }
   ```
   



##########
be/src/vec/common/hash_table/hash_map_context.h:
##########
@@ -126,6 +126,10 @@ struct MethodBase {
         }
     }
 
+    std::span<Key> get_keys() const { return {keys, hash_values.size()}; }

Review Comment:
   warning: function 'get_keys' should be marked [[nodiscard]] [modernize-use-nodiscard]
   
   ```suggestion
       [[nodiscard]] std::span<Key> get_keys() const { return {keys, hash_values.size()}; }
   ```
   



-- 
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-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] save code [doris]

Posted by "HappenLee (via GitHub)" <gi...@apache.org>.
HappenLee closed pull request #25278: save code
URL: https://github.com/apache/doris/pull/25278


-- 
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-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org