Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](hash)update_hashes_with_value method should handle if input value is null #13332

Merged
merged 2 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions be/src/vec/columns/column_decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,18 @@ template <typename T>
void ColumnDecimal<T>::update_hashes_with_value(uint64_t* __restrict hashes,
const uint8_t* __restrict null_data) const {
auto s = size();
for (int i = 0; i < s; i++) {
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]), sizeof(T),
hashes[i]);
if (null_data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to express the logic as the following to save LOC?

     for (int i = 0; i < s; i++) {
        if (null_data != nullptr && null_data[i] != 0) continue;
        hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]), sizeof(T),
                                               hashes[i]);
     }

for (int i = 0; i < s; i++) {
if (null_data[i] == 0) {
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]),
sizeof(T), hashes[i]);
}
}
} else {
for (int i = 0; i < s; i++) {
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]),
sizeof(T), hashes[i]);
}
}
}

Expand Down
21 changes: 16 additions & 5 deletions be/src/vec/columns/column_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,22 @@ class ColumnString final : public COWHelper<IColumn, ColumnString> {
void update_hashes_with_value(uint64_t* __restrict hashes,
const uint8_t* __restrict null_data) const override {
auto s = size();
for (int i = 0; i < s; i++) {
size_t string_size = size_at(i);
size_t offset = offset_at(i);
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&chars[offset]),
string_size, hashes[i]);
if (null_data) {
for (int i = 0; i < s; i++) {
if (null_data[i] == 0) {
size_t string_size = size_at(i);
size_t offset = offset_at(i);
hashes[i] = HashUtil::xxHash64WithSeed(
reinterpret_cast<const char*>(&chars[offset]), string_size, hashes[i]);
}
}
} else {
for (int i = 0; i < s; i++) {
size_t string_size = size_at(i);
size_t offset = offset_at(i);
hashes[i] = HashUtil::xxHash64WithSeed(
reinterpret_cast<const char*>(&chars[offset]), string_size, hashes[i]);
}
}
}

Expand Down
15 changes: 12 additions & 3 deletions be/src/vec/columns/column_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,18 @@ template <typename T>
void ColumnVector<T>::update_hashes_with_value(uint64_t* __restrict hashes,
const uint8_t* __restrict null_data) const {
auto s = size();
for (int i = 0; i < s; i++) {
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]), sizeof(T),
hashes[i]);
if (null_data) {
for (int i = 0; i < s; i++) {
if (null_data[i] == 0) {
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]),
sizeof(T), hashes[i]);
}
}
} else {
for (int i = 0; i < s; i++) {
hashes[i] = HashUtil::xxHash64WithSeed(reinterpret_cast<const char*>(&data[i]),
sizeof(T), hashes[i]);
}
}
}

Expand Down