From ddc20e6683b68fe4df7ad20178d1e1a9463d3be4 Mon Sep 17 00:00:00 2001 From: Pradeep Vaka Date: Tue, 4 Feb 2025 20:11:28 -0800 Subject: [PATCH] feat: Add combine_hash internal operator (#12244) Summary: Pull Request resolved: https://github.com/facebookincubator/velox/pull/12244 Add combine_hash internal function to unblock join prefilter optimization in Prestissimo. Reviewed By: Yuhta Differential Revision: D69007969 fbshipit-source-id: 037ef0e54034c75023bb0d1af5d1b961a0a6f610 --- velox/functions/prestosql/IntegerFunctions.h | 16 ++++++++++++++++ .../IntegerFunctionsRegistration.cpp | 3 +++ 2 files changed, 19 insertions(+) diff --git a/velox/functions/prestosql/IntegerFunctions.h b/velox/functions/prestosql/IntegerFunctions.h index bb6a6cccbfce..fa2fadafe453 100644 --- a/velox/functions/prestosql/IntegerFunctions.h +++ b/velox/functions/prestosql/IntegerFunctions.h @@ -35,4 +35,20 @@ struct XxHash64BigIntFunction { } }; +// combine_hash(bigint, bigint) → bigint +template +struct CombineHashFunction { + VELOX_DEFINE_FUNCTION_TYPES(T); + + FOLLY_ALWAYS_INLINE + void call( + out_type& result, + const arg_type& previousHashValue, + const arg_type& input) { + result = static_cast( + 31 * static_cast(previousHashValue) + + static_cast(input)); + } +}; + } // namespace facebook::velox::functions diff --git a/velox/functions/prestosql/registration/IntegerFunctionsRegistration.cpp b/velox/functions/prestosql/registration/IntegerFunctionsRegistration.cpp index 5fdd332a2056..80cc574c61d4 100644 --- a/velox/functions/prestosql/registration/IntegerFunctionsRegistration.cpp +++ b/velox/functions/prestosql/registration/IntegerFunctionsRegistration.cpp @@ -23,6 +23,9 @@ namespace { void registerSimpleFunctions(const std::string& prefix) { registerFunction( {prefix + "xxhash64_internal"}); + + registerFunction( + {prefix + "combine_hash_internal"}); } } // namespace