hello-stephen commented on code in PR #71340:
URL: https://github.com/apache/doris/pull/71340#discussion_r4787571313


##########
be/src/core/column/column_nullable.cpp:
##########
@@ -130,7 +130,9 @@ void ColumnNullable::update_xxHash_with_value(size_t start, 
size_t end, uint64_t
         const auto* __restrict real_null_data = 
get_null_map_column().get_data().data();
         for (size_t i = start; i < end; ++i) {
             if (real_null_data[i] != 0) {
-                hash = HashUtil::xxHash64NullWithSeed(hash);
+                // Use a one-based position relative to the range so the first 
NULL
+                // differs from INT 0 and the hash is independent of the 
range's offset.
+                hash = HashUtil::xxHash64NullWithSeed(hash + (i - start + 1));

Review Comment:
   [P2] Update the constant-NULL hash assertion
   
   `ColumnConstTest.update_xxHash_with_value` in 
`be/test/core/column/column_const_test.cpp` wraps a single NULL and passes seed 
0. `ColumnConst` forwards `[0, 1)` to this method, which now hashes that NULL 
with seed 1. The test still expects the seed-0 digest `5238470482016868669ULL` 
and will fail. Update that assertion to match the intended NULL hash contract.



##########
be/src/core/column/column_array.cpp:
##########
@@ -368,30 +368,18 @@ void ColumnArray::update_hash_with_value(size_t n, 
SipHash& hash) const {
 // for every array row calculate xxHash
 void ColumnArray::update_xxHash_with_value(size_t start, size_t end, uint64_t& 
hash,
                                            const uint8_t* __restrict 
null_data) const {
-    auto& offsets_column = get_offsets();
-    if (null_data) {
-        for (size_t i = start; i < end; ++i) {
-            if (null_data[i] == 0) {
-                size_t elem_size = offsets_column[i] - offsets_column[i - 1];
-                if (elem_size == 0) {
-                    hash = HashUtil::xxHash64WithSeed(reinterpret_cast<const 
char*>(&elem_size),
-                                                      sizeof(elem_size), hash);
-                } else {
-                    get_data().update_xxHash_with_value(offsets_column[i - 1], 
offsets_column[i],
-                                                        hash, nullptr);
-                }
-            }
+    const auto& offsets_column = get_offsets();
+    for (size_t i = start; i < end; ++i) {
+        if (null_data && null_data[i] != 0) {
+            continue;
         }
-    } else {
-        for (size_t i = start; i < end; ++i) {
-            size_t elem_size = offsets_column[i] - offsets_column[i - 1];
-            if (elem_size == 0) {
-                hash = HashUtil::xxHash64WithSeed(reinterpret_cast<const 
char*>(&elem_size),
-                                                  sizeof(elem_size), hash);
-            } else {
-                get_data().update_xxHash_with_value(offsets_column[i - 1], 
offsets_column[i], hash,
-                                                    nullptr);
-            }
+
+        const size_t offset = offsets_column[i - 1];
+        const size_t elem_size = offsets_column[i] - offset;
+        hash = HashUtil::xxHash64WithSeed(reinterpret_cast<const 
char*>(&elem_size),

Review Comment:
   [P1] Preserve array distinct keys across upgrades
   
   This changes the only equality key stored by 
`multi_distinct_count(ARRAY<INT>)`. For example, the old implementation hashes 
`[1]` directly from seed 0, while this code hashes its length first. 
`aggregate_function_uniq.h` serializes and unions the raw `UInt64` keys, so 
partial states from old and new BEs can count `[1]` twice. The same problem 
occurs when merging persisted `multi_distinct_count_state` values written 
before and after upgrade. Use a common key scheme during rolling upgrades and 
handle legacy persisted states explicitly. Their digests alone cannot be 
converted to the new scheme.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to