Skip to content

Commit

Permalink
Merge pull request ClickHouse#36467 from olevino/wyhash
Browse files Browse the repository at this point in the history
Wyhash
  • Loading branch information
yakov-olkhovskiy authored May 11, 2022
2 parents 3215c98 + e04dc44 commit 6d3a54a
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,6 @@
[submodule "contrib/minizip-ng"]
path = contrib/minizip-ng
url = https://github.com/zlib-ng/minizip-ng
[submodule "contrib/wyhash"]
path = contrib/wyhash
url = https://github.com/wangyi-fudan/wyhash.git
1 change: 1 addition & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ if (ENABLE_FUZZING)
add_contrib (libprotobuf-mutator-cmake libprotobuf-mutator)
endif()

add_contrib (wyhash-cmake wyhash)
add_contrib (cityhash102)
add_contrib (libfarmhash)
add_contrib (icu-cmake icu)
Expand Down
1 change: 1 addition & 0 deletions contrib/wyhash
Submodule wyhash added at 991aa3
3 changes: 3 additions & 0 deletions contrib/wyhash-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_library(wyhash INTERFACE)
target_include_directories(wyhash SYSTEM BEFORE INTERFACE "${ClickHouse_SOURCE_DIR}/contrib/wyhash")
add_library(ch_contrib::wyhash ALIAS wyhash)
1 change: 1 addition & 0 deletions docker/test/fasttest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function clone_submodules
contrib/NuRaft
contrib/jemalloc
contrib/replxx
contrib/wyhash
)

git submodule sync
Expand Down
1 change: 1 addition & 0 deletions src/Functions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library(clickhouse_functions ${clickhouse_functions_sources})

target_link_libraries(clickhouse_functions
PUBLIC
ch_contrib::wyhash
ch_contrib::cityhash
ch_contrib::farmhash
clickhouse_dictionaries
Expand Down
2 changes: 2 additions & 0 deletions src/Functions/FunctionsHashing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@ void registerFunctionsHashing(FunctionFactory & factory)

factory.registerFunction<FunctionXxHash32>();
factory.registerFunction<FunctionXxHash64>();

factory.registerFunction<FunctionWyHash64>();
}
}
26 changes: 26 additions & 0 deletions src/Functions/FunctionsHashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <metrohash.h>
#include <MurmurHash2.h>
#include <MurmurHash3.h>
#include <wyhash.h>

#include "config_functions.h"
#include "config_core.h"
Expand Down Expand Up @@ -1369,6 +1370,29 @@ class FunctionURLHash : public IFunction
}
};

struct ImplWyHash64
{
static constexpr auto name = "wyHash64";
using ReturnType = UInt64;

static UInt64 apply(const char * s, const size_t len)
{
return wyhash(s, len, 0, _wyp);
}
static UInt64 combineHashes(UInt64 h1, UInt64 h2)
{
union
{
UInt64 u64[2];
char chars[16];
};
u64[0] = h1;
u64[1] = h2;
return apply(chars, 16);
}

static constexpr bool use_int_hash_for_pods = false;
};

struct NameIntHash32 { static constexpr auto name = "intHash32"; };
struct NameIntHash64 { static constexpr auto name = "intHash64"; };
Expand Down Expand Up @@ -1406,4 +1430,6 @@ using FunctionHiveHash = FunctionAnyHash<HiveHashImpl>;
using FunctionXxHash32 = FunctionAnyHash<ImplXxHash32>;
using FunctionXxHash64 = FunctionAnyHash<ImplXxHash64>;

using FunctionWyHash64 = FunctionAnyHash<ImplWyHash64>;

}
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/02286_function_wyhash.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\N
4808886099364463827
10557035923789874751
10561902096955922022
5 changes: 5 additions & 0 deletions tests/queries/0_stateless/02286_function_wyhash.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT wyHash64(NULL);
SELECT wyHash64('');
SELECT wyHash64(' ');
SELECT wyHash64('qwerty');

0 comments on commit 6d3a54a

Please sign in to comment.