diff --git a/dbms/include/DB/Functions/FunctionsHashing.h b/dbms/include/DB/Functions/FunctionsHashing.h index 7143f0aa39d..b356df55eb9 100644 --- a/dbms/include/DB/Functions/FunctionsHashing.h +++ b/dbms/include/DB/Functions/FunctionsHashing.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -839,6 +840,25 @@ struct ImplFarmHash64 static auto Hash64(const char * const s, const std::size_t len) { return farmhash::Hash64(s, len); } }; +struct ImplMetroHash64 +{ + static constexpr auto name = "metroHash64"; + using uint128_t = uint128; + + static auto Hash128to64(const uint128_t & x) { return ::Hash128to64(x); } + static auto Hash64(const char * const s, const std::size_t len) + { + union { + std::uint64_t u64; + std::uint8_t u8[sizeof(u64)]; + }; + + metrohash64_1(reinterpret_cast(s), len, 0, u8); + + return u64; + } +}; + using FunctionHalfMD5 = FunctionStringHash64; using FunctionSipHash64 = FunctionStringHash64; using FunctionIntHash32 = FunctionIntHash; @@ -850,5 +870,6 @@ using FunctionSHA256 = FunctionStringHashFixedString; using FunctionSipHash128 = FunctionStringHashFixedString; using FunctionCityHash64 = FunctionNeighbourhoodHash64; using FunctionFarmHash64 = FunctionNeighbourhoodHash64; +using FunctionMetroHash64 = FunctionNeighbourhoodHash64; } diff --git a/dbms/src/Functions/FunctionsHashing.cpp b/dbms/src/Functions/FunctionsHashing.cpp index 801c5a3370f..afe970d3180 100644 --- a/dbms/src/Functions/FunctionsHashing.cpp +++ b/dbms/src/Functions/FunctionsHashing.cpp @@ -16,6 +16,7 @@ void registerFunctionsHashing(FunctionFactory & factory) factory.registerFunction(); factory.registerFunction(); factory.registerFunction(); + factory.registerFunction(); factory.registerFunction(); factory.registerFunction(); factory.registerFunction();