A SQLCLR SAFE implementation of XXHash3.NET's xxHash64 code returning a SqlInt64, that can be deployed to SQL Server or Azure SQL Managed Instance.
Note that only SAFE assemblies are supported on Linux and as such only Supported Libraries may be referenced in the assembly. XXHash3.NET's code base has been modififed to meet this requirement.
- Compile the SqlXxHash3.sln to a .NET Framework 4.8 assembly named SqlXxHash3Net.dll
- Copy SqlXxHash3Net.dll to a location accessible by SQL Server.
- Create the assembly in a database:
create assembly xxhash64 from 'c:/tmp/CLR/SqlXxHash3Net.dll' with permission_set = safe;
- Create a function referencing the method to be called:
create function dbo.XxHash64(@Value varbinary(max))
returns bigint
external name xxhash64.XXHash64Net.HashToInt64;
- Test it...
declare @vb varbinary(max) = convert(varbinary, 'Hello World!');
select dbo.XxHash64(@vb);
- Verfiy it...
-6545093196672709231 is a52b286a3e7f4d91, which matches the output from Generate a xxh hash value
- Declare (more) victory!