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

[Refactor] Add default hash func template for phmap #49736

Merged
merged 8 commits into from
Sep 19, 2024

Conversation

trueeyu
Copy link
Contributor

@trueeyu trueeyu commented Aug 13, 2024

Why I'm doing:

What I'm doing:

  • Define a general phmap hash func to avoid writing a lot of if else.
  • Fix the hash scatter problem of Decimal128

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

Documentation PRs only:

If you are submitting a PR that adds or changes English documentation and have not
included Chinese documentation, then you can check the box to request GPT to translate the
English doc to Chinese. Please ensure to uncheck the Do not translate box if translation is needed.
The workflow will generate a new PR with the Chinese translation after this PR is merged.

  • Yes, translate English markdown files with GPT
  • Do not translate

@trueeyu trueeyu requested a review from a team as a code owner August 13, 2024 02:24
@trueeyu trueeyu changed the title Add default hash func template for phmap [Refactor] Add default hash func template for phmap Aug 13, 2024
static_assert(lt_is_largeint<LT> || lt_is_fixedlength<LT> || lt_is_string<LT>);

return _array_intersect<phmap::flat_hash_set<CppTypeWithOverlapTimes, CppTypeWithOverlapTimesHash<LT>,
CppTypeWithOverlapTimesEqual>>(columns);
}

private:
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
Missing condition for lt_is_decimal128 in the static assertion check within the process function of the _array_intersect implementation.

You can modify the code like this:

        static_assert(lt_is_largeint<LT> || lt_is_fixedlength<LT> || lt_is_string<LT> || lt_is_decimal128<LT>);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lt_is_decimal128 is not supported here

|| lt_is_string<LT> || lt_is_binary<LT>;
}
};

} // namespace starrocks
Copy link

Choose a reason for hiding this comment

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

The most risky bug in this code is:
The function is_supported() has an incorrect static assertion condition inside the operator(). This could cause runtime errors for unsupported types.

You can modify the code like this:

template <LogicalType LT, PhmapSeed seed>
struct PhmapDefaultHashFunc {
    std::size_t operator()(const RunTimeCppType<LT>& value) const {
        static_assert(is_supported(), "Unsupported LogicalType");

        if constexpr (lt_is_largeint<LT> || lt_is_decimal128<LT>) {
            return Hash128WithSeed<seed>()(value);
        } else if constexpr (lt_is_fixedlength<LT>) {
            return StdHashWithSeed<RunTimeCppType<LT>, seed>()(value);
        } else if constexpr (lt_is_string<LT> || lt_is_binary<LT>) {
            return SliceHashWithSeed<seed>()(value);
        } else {
            assert(false);
            return 0; // Add a return statement to handle the false case
        }
    }

    constexpr static bool is_supported() {
        return lt_is_largeint<LT> || lt_is_decimal128<LT> || lt_is_fixedlength<LT>
               || lt_is_string<LT> || lt_is_binary<LT>;
    }
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion, fixed.

@trueeyu trueeyu changed the title [Refactor] Add default hash func template for phmap [WIP][Refactor] Add default hash func template for phmap Sep 10, 2024
@trueeyu trueeyu changed the title [WIP][Refactor] Add default hash func template for phmap [Refactor] Add default hash func template for phmap Sep 10, 2024
@trueeyu
Copy link
Contributor Author

trueeyu commented Sep 18, 2024

https://github.com/Mergifyio rebase main

Copy link
Contributor

mergify bot commented Sep 18, 2024

rebase main

✅ Branch has been successfully rebased

@trueeyu
Copy link
Contributor Author

trueeyu commented Sep 18, 2024

https://github.com/Mergifyio rebase main

Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Signed-off-by: trueeyu <[email protected]>
Copy link
Contributor

mergify bot commented Sep 18, 2024

rebase main

✅ Branch has been successfully rebased

Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[BE Incremental Coverage Report]

fail : 0 / 9 (00.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 be/src/column/column_hash.h 0 4 00.00% [350, 354, 356, 358]
🔵 be/src/exprs/array_functions.tpp 0 4 00.00% [42, 264, 366, 380]
🔵 be/src/exec/schema_scanner/schema_views_scanner.cpp 0 1 00.00% [38]

@wanpengfei-git wanpengfei-git merged commit 809192e into StarRocks:main Sep 19, 2024
39 of 40 checks passed
@trueeyu
Copy link
Contributor Author

trueeyu commented Sep 29, 2024

https://github.com/Mergifyio backport branch-3.3

Copy link
Contributor

mergify bot commented Sep 29, 2024

backport branch-3.3

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 29, 2024
@trueeyu
Copy link
Contributor Author

trueeyu commented Sep 29, 2024

https://github.com/Mergifyio backport branch-3.2

Copy link
Contributor

mergify bot commented Sep 29, 2024

backport branch-3.2

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 29, 2024
Signed-off-by: trueeyu <[email protected]>
(cherry picked from commit 809192e)

# Conflicts:
#	test/sql/test_array_fn/R/test_array_fn
wanpengfei-git pushed a commit that referenced this pull request Sep 29, 2024
@trueeyu
Copy link
Contributor Author

trueeyu commented Sep 29, 2024

https://github.com/Mergifyio backport branch-3.1

Copy link
Contributor

mergify bot commented Sep 29, 2024

backport branch-3.1

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Sep 29, 2024
Signed-off-by: trueeyu <[email protected]>
(cherry picked from commit 809192e)

# Conflicts:
#	be/src/exec/schema_scanner/schema_views_scanner.h
#	test/sql/test_array_fn/R/test_array_fn
wanpengfei-git pushed a commit that referenced this pull request Sep 29, 2024
renzhimin7 pushed a commit to renzhimin7/starrocks that referenced this pull request Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants