ReferenceSQL ReferenceFunctions

Hash

Hash functions reference.

BLAKE3

Calculates BLAKE3 hash string and returns the resulting set of bytes as FixedString. This cryptographic hash-function is integrated into RawTree with BLAKE3 Rust library. The function is rather fast and shows approximately two times faster performance compared to SHA-2, while generating hashes of the same length as SHA-256. It returns a BLAKE3 hash as a byte array with type FixedString(32).

Syntax

BLAKE3(message)

Arguments

  • message — The input string to hash. String

Returned value

Returns the 32-byte BLAKE3 hash of the input string as a fixed-length string. FixedString(32)

Examples

hash

SELECT hex(BLAKE3('ABC'))
┌─hex(BLAKE3('ABC'))───────────────────────────────────────────────┐
│ D1717274597CF0289694F75D96D444B992A096F1AFD8E7BBFA6EBB1D360FEDFC │
└──────────────────────────────────────────────────────────────────┘

Introduced in version 22.10.

MD4

Calculates the MD4 hash of the given string.

Syntax

MD4(s)

Arguments

  • s — The input string to hash. String

Returned value

Returns the MD4 hash of the given input string as a fixed-length string. FixedString(16)

Examples

Usage example

SELECT HEX(MD4('abc'));
┌─hex(MD4('abc'))──────────────────┐
│ A448017AAF21D8525FC10AE87AA6729D │
└──────────────────────────────────┘

Introduced in version 21.11.

MD5

Calculates the MD5 hash of the given string.

Syntax

MD5(s)

Arguments

  • s — The input string to hash. String

Returned value

Returns the MD5 hash of the given input string as a fixed-length string. FixedString(16)

Examples

Usage example

SELECT HEX(MD5('abc'));
┌─hex(MD5('abc'))──────────────────┐
│ 900150983CD24FB0D6963F7D28E17F72 │
└──────────────────────────────────┘

Introduced in version 1.1.

RIPEMD160

Calculates the RIPEMD-160 hash of the given string.

Syntax

RIPEMD160(s)

Arguments

  • s — The input string to hash. String

Returned value

Returns the RIPEMD160 hash of the given input string as a fixed-length string. FixedString(20)

Examples

Usage example

SELECT HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'));
┌─HEX(RIPEMD160('The quick brown fox jumps over the lazy dog'))─┐
│ 37F332F68DB77BD9D7EDD4969571AD671CF9DD3B                      │
└───────────────────────────────────────────────────────────────┘

Introduced in version 24.10.

SHA1

Calculates the SHA1 hash of the given string.

Syntax

SHA1(s)

Arguments

  • s — The input string to hash String

Returned value

Returns the SHA1 hash of the given input string as a fixed-length string. FixedString(20)

Examples

Usage example

SELECT HEX(SHA1('abc'));
┌─hex(SHA1('abc'))─────────────────────────┐
│ A9993E364706816ABA3E25717850C26C9CD0D89D │
└──────────────────────────────────────────┘

Introduced in version 1.1.

SHA224

Calculates the SHA224 hash of the given string.

Syntax

SHA224(s)

Arguments

  • s — The input value to hash. String

Returned value

Returns the SHA224 hash of the given input string as a fixed-length string. FixedString(28)

Examples

Usage example

SELECT HEX(SHA224('abc'));
┌─hex(SHA224('abc'))───────────────────────────────────────┐
│ 23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7 │
└──────────────────────────────────────────────────────────┘

Introduced in version 1.1.

SHA256

Calculates the SHA256 hash of the given string.

Syntax

SHA256(s)

Arguments

  • s — The input string to hash. String

Returned value

Returns the SHA256 hash of the given input string as a fixed-length string. FixedString(32)

Examples

Usage example

SELECT HEX(SHA256('abc'));
┌─hex(SHA256('abc'))───────────────────────────────────────────────┐
│ BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD │
└──────────────────────────────────────────────────────────────────┘

Introduced in version 1.1.

SHA384

Calculates the SHA384 hash of the given string.

Syntax

SHA384(s)

Arguments

  • s — The input string to hash. String

Returned value

Returns the SHA384 hash of the given input string as a fixed-length string. FixedString(48)

Examples

Usage example

SELECT HEX(SHA384('abc'));
┌─hex(SHA384('abc'))───────────────────────────────────────────────────────────────────────────────┐
│ CB00753F45A35E8BB5A03D699AC65007272C32AB0EDED1631A8B605A43FF5BED8086072BA1E7CC2358BAECA134C825A7 │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘

Introduced in version 1.1.

SHA512

Calculates the SHA512 hash of the given string.

Syntax

SHA512(s)

Arguments

  • s — The input string to hash String

Returned value

Returns the SHA512 hash of the given input string as a fixed-length string. FixedString(64)

Examples

Usage example

SELECT HEX(SHA512('abc'));
┌─hex(SHA512('abc'))───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Introduced in version 1.1.

SHA512_256

Calculates the SHA512_256 hash of the given string.

Syntax

SHA512_256(s)

Arguments

  • s — The input string to hash. String

Returned value

Returns the SHA512_256 hash of the given input string as a fixed-length string. FixedString(32)

Examples

Usage example

SELECT HEX(SHA512_256('abc'));
┌─hex(SHA512_256('abc'))───────────────────────────────────────────┐
│ 53048E2681941EF99B2E29B76B4C7DABE4C2D0C634FC6D46E0E2F13107E7AF23 │
└──────────────────────────────────────────────────────────────────┘

Introduced in version 1.1.

URLHash

A fast, decent-quality non-cryptographic hash function for a string obtained from a URL using some type of normalization.

This hash function has two modes:

ModeDescription
URLHash(url)Calculates a hash from a string without one of the trailing symbols /,? or # at the end, if present.
URLHash(url, N)Calculates a hash from a string up to the N level in the URL hierarchy, without one of the trailing symbols /,? or # at the end, if present. Levels are the same as in URLHierarchy.

Syntax

URLHash(url[, N])

Arguments

  • url — URL string to hash. String
  • N — Optional. Level in the URL hierarchy. (U)Int*

Returned value

Returns the computed hash value of url. UInt64

Examples

Usage example

SELECT URLHash('https://www.rawtree.com')
┌─URLHash('htt⋯house.com')─┐
│     13614512636072854701 │
└──────────────────────────┘

Hash of url with specified level

SELECT URLHash('https://www.rawtree.com/docs', 0);
SELECT URLHash('https://www.rawtree.com/docs', 1);
-- hash of https://www.rawtree.com
┌─URLHash('htt⋯m/docs', 0)─┐
│     13614512636072854701 │
└──────────────────────────┘
-- hash of https://www.rawtree.com/docs
┌─URLHash('htt⋯m/docs', 1)─┐
│     13167253331440520598 │
└──────────────────────────┘

Introduced in version 1.1.

cityHash64

Produces a 64-bit CityHash hash value.

This is a fast non-cryptographic hash function. It uses the CityHash algorithm for string parameters and implementation-specific fast non-cryptographic hash function for parameters with other data types. The function uses the CityHash combinator to get the final results.

:::info Google changed the algorithm of CityHash after it was added to RawTree. In other words, RawTree's cityHash64 and Google's upstream CityHash now produce different results. RawTree cityHash64 corresponds to CityHash v1.0.2. :::

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

cityHash64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash of the input arguments. UInt64

Examples

Call example

SELECT cityHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS CityHash, toTypeName(CityHash) AS type;
┌─────────────CityHash─┬─type───┐
│ 12072650598913549138 │ UInt64 │
└──────────────────────┴────────┘

Computing the checksum of the entire table with accuracy up to the row order

CREATE TABLE users (
    id UInt32,
    name String,
    age UInt8,
    city String
)
ENGINE = MergeTree
ORDER BY tuple();

INSERT INTO users VALUES
(1, 'Alice', 25, 'New York'),
(2, 'Bob', 30, 'London'),
(3, 'Charlie', 35, 'Tokyo');

SELECT groupBitXor(cityHash64(*)) FROM users;
┌─groupBitXor(⋯age, city))─┐
│     11639977218258521182 │
└──────────────────────────┘

Introduced in version 1.1.

farmFingerprint64

Produces a 64-bit FarmHash value using the Fingerprint64 method.

:::tip farmFingerprint64 is preferred for a stable and portable value over farmHash64. :::

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

farmFingerprint64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash value of the input arguments. UInt64

Examples

Usage example

SELECT farmFingerprint64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmFingerprint, toTypeName(FarmFingerprint) AS type;
┌─────FarmFingerprint─┬─type───┐
│ 5752020380710916328 │ UInt64 │
└─────────────────────┴────────┘

Introduced in version 20.12.

farmHash64

Produces a 64-bit FarmHash using the Hash64 method.

:::tip farmFingerprint64 is preferred for a stable and portable value. :::

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

farmHash64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash value of the input arguments. UInt64

Examples

Usage example

SELECT farmHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS FarmHash, toTypeName(FarmHash) AS type;
┌─────────────FarmHash─┬─type───┐
│ 18125596431186471178 │ UInt64 │
└──────────────────────┴────────┘

Introduced in version 1.1.

gccMurmurHash

Computes the 64-bit MurmurHash2 hash of the input value using the same seed as used by GCC.

It is portable between Clang and GCC builds.

Syntax

gccMurmurHash(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of arguments for which to compute the hash. Any

Returned value

Returns the calculated hash value of the input arguments. UInt64

Examples

Usage example

SELECT
    gccMurmurHash(1, 2, 3) AS res1,
    gccMurmurHash(('a', [1, 2, 3], 4, (4, ['foo', 'bar'], 1, (1, 2)))) AS res2
┌─────────────────res1─┬────────────────res2─┐
│ 12384823029245979431 │ 1188926775431157506 │
└──────────────────────┴─────────────────────┘

Introduced in version 20.1.

halfMD5

Interprets all the input parameters as strings and calculates the MD5 hash value for each of them. Then combines hashes, takes the first 8 bytes of the hash of the resulting string, and interprets them as UInt64 in big-endian byte order. The function is relatively slow (5 million short strings per second per processor core).

Consider using the sipHash64 function instead.

The function takes a variable number of input parameters. Arguments can be any of the supported data types. For some data types calculated value of hash function may be the same for the same values even if types of arguments differ (integers of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data).

Syntax

halfMD5(arg1[, arg2, ..., argN])

Arguments

  • arg1[, arg2, ..., argN] — Variable number of arguments for which to compute the hash. Any

Returned value

Returns the computed half MD5 hash of the given input params returned as a UInt64 in big-endian byte order. UInt64

Examples

Usage example

SELECT HEX(halfMD5('abc', 'cde', 'fgh'));
┌─hex(halfMD5('abc', 'cde', 'fgh'))─┐
│ 2C9506B7374CFAF4                  │
└───────────────────────────────────┘

Introduced in version 1.1.

hiveHash

Calculates a "HiveHash" from a string. This is just JavaHash with zeroed out sign bits. This function is used in Apache Hive for versions before 3.0.

:::caution This hash function is unperformant. Use it only when this algorithm is already used in another system and you need to calculate the same result. :::

Syntax

hiveHash(arg)

Arguments

  • arg — Input string to hash. String

Returned value

Returns the computed "hive hash" of the input string. Int32

Examples

Usage example

SELECT hiveHash('Hello, world!');
┌─hiveHash('Hello, world!')─┐
│                 267439093 │
└───────────────────────────┘

Introduced in version 20.1.

icebergHash

Implements the logic of the iceberg hashing transform

Syntax

icebergHash(value)

Arguments

Returned value

Returns a 32-bit Murmur3 hash, x86 variant, seeded with 0 Int32

Examples

Example

SELECT icebergHash(1.0 :: Float32)
-142385009

Introduced in version 25.5.

intHash32

Calculates a 32-bit hash of an integer.

The hash function is relatively fast but not cryptographic hash function.

Syntax

intHash32(arg)

Arguments

Returned value

Returns the computed 32-bit hash code of the input integer UInt32

Examples

Usage example

SELECT intHash32(42);
┌─intHash32(42)─┐
│    1228623923 │
└───────────────┘

Introduced in version 1.1.

intHash64

Calculates a 64-bit hash of an integer.

The hash function is relatively fast (even faster than intHash32) but not a cryptographic hash function.

Syntax

intHash64(int)

Arguments

Returned value

64-bit hash code. UInt64

Examples

Usage example

SELECT intHash64(42);
┌────────intHash64(42)─┐
│ 11490350930367293593 │
└──────────────────────┘

Introduced in version 1.1.

javaHash

Calculates JavaHash from:

:::caution This hash function is unperformant. Use it only when this algorithm is already in use in another system and you need to calculate the same result. :::

:::note Java only supports calculating the hash of signed integers, so if you want to calculate a hash of unsigned integers you must cast them to the proper signed RawTree types. :::

Syntax

javaHash(arg)

Arguments

  • arg — Input value to hash. Any

Returned value

Returns the computed hash of arg Int32

Examples

Usage example 1

SELECT javaHash(toInt32(123));
┌─javaHash(toInt32(123))─┐
│               123      │
└────────────────────────┘

Usage example 2

SELECT javaHash('Hello, world!');
┌─javaHash('Hello, world!')─┐
│               -1880044555 │
└───────────────────────────┘

Introduced in version 20.1.

javaHashUTF16LE

Calculates JavaHash from a string, assuming it contains bytes representing a string in UTF-16LE encoding.

Syntax

javaHashUTF16LE(arg)

Arguments

  • arg — A string in UTF-16LE encoding. String

Returned value

Returns the computed hash of the UTF-16LE encoded string. Int32

Examples

Usage example

SELECT javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'));
┌─javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'))─┐
│                                                      3556498 │
└──────────────────────────────────────────────────────────────┘

Introduced in version 20.1.

jumpConsistentHash

Calculates the jump consistent hash for an integer.

Syntax

jumpConsistentHash(key, buckets)

Arguments

  • key — The input key. UInt64
  • buckets — The number of buckets. Int32

Returned value

Returns the computed hash value. Int32

Examples

Usage example

SELECT jumpConsistentHash(256, 4)
┌─jumpConsistentHash(256, 4)─┐
│                          3 │
└────────────────────────────┘

Introduced in version 1.1.

kafkaMurmurHash

Calculates the 32-bit MurmurHash2 hash of the input value using the same seed as used by Kafka and without the highest bit to be compatible with Default Partitioner.

Syntax

kafkaMurmurHash(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of parameters for which to compute the hash. Any

Returned value

Returns the calculated hash value of the input arguments. UInt32

Examples

Usage example

SELECT
    kafkaMurmurHash('foobar') AS res1,
    kafkaMurmurHash(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS res2
┌───────res1─┬─────res2─┐
│ 1357151166 │ 85479775 │
└────────────┴──────────┘

Introduced in version 23.4.

keccak256

Calculates the Keccak-256 cryptographic hash of the given string. This hash function is widely used in blockchain applications, particularly Ethereum.

Syntax

keccak256(message)

Arguments

  • message — The input string to hash. String

Returned value

Returns the 32-byte Keccak-256 hash of the input string as a fixed-length string. FixedString(32)

Examples

Usage example

SELECT hex(keccak256('hello'))
┌─hex(keccak256('hello'))──────────────────────────────────────────┐
│ 1C8AFF950685C2ED4BC3174F3472287B56D9517B9C948127319A09A7A36DEAC8 │
└──────────────────────────────────────────────────────────────────┘

Introduced in version 25.4.

kostikConsistentHash

An O(1) time and space consistent hash algorithm by Konstantin 'Kostik' Oblakov. Only efficient with n <= 32768.

Syntax

kostikConsistentHash(input, n)

Arguments

  • input — An integer key. UInt64
  • n — The number of buckets. UInt16

Returned value

Returns the computed hash value. UInt16

Examples

Usage example

SELECT kostikConsistentHash(16045690984833335023, 2);
┌─kostikConsistentHash(16045690984833335023, 2)─┐
│                                             1 │
└───────────────────────────────────────────────┘

Introduced in version 22.6.

metroHash64

Produces a 64-bit MetroHash hash value.

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

metroHash64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash of the input arguments. UInt64

Examples

Usage example

SELECT metroHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MetroHash, toTypeName(MetroHash) AS type;
┌────────────MetroHash─┬─type───┐
│ 14235658766382344533 │ UInt64 │
└──────────────────────┴────────┘

Introduced in version 1.1.

murmurHash2_32

Computes the MurmurHash2 hash of the input value.

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

murmurHash2_32(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash value of the input arguments. UInt32

Examples

Usage example

SELECT murmurHash2_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type;
┌─MurmurHash2─┬─type───┐
│  3681770635 │ UInt32 │
└─────────────┴────────┘

Introduced in version 18.5.

murmurHash2_64

Computes the MurmurHash2 hash of the input value.

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

murmurHash2_64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash of the input arguments. UInt64

Examples

Usage example

SELECT murmurHash2_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash2, toTypeName(MurmurHash2) AS type;
┌──────────MurmurHash2─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘

Introduced in version 18.10.

murmurHash3_128

Computes the 128-bit MurmurHash3 hash of the input value.

Syntax

murmurHash3_128(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed 128-bit MurmurHash3 hash value of the input arguments. FixedString(16)

Examples

Usage example

SELECT hex(murmurHash3_128('foo', 'foo', 'foo'));
┌─hex(murmurHash3_128('foo', 'foo', 'foo'))─┐
│ F8F7AD9B6CD4CF117A71E277E2EC2931          │
└───────────────────────────────────────────┘

Introduced in version 18.10.

murmurHash3_32

Produces a MurmurHash3 hash value.

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

murmurHash3_32(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash value of the input arguments. UInt32

Examples

Usage example

SELECT murmurHash3_32(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
┌─MurmurHash3─┬─type───┐
│     2152717 │ UInt32 │
└─────────────┴────────┘

Introduced in version 18.10.

murmurHash3_64

Computes the MurmurHash3 hash of the input value.

:::note The calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

murmurHash3_64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed hash value of the input arguments. UInt64

Examples

Usage example

SELECT murmurHash3_64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS MurmurHash3, toTypeName(MurmurHash3) AS type;
┌──────────MurmurHash3─┬─type───┐
│ 11832096901709403633 │ UInt64 │
└──────────────────────┴────────┘

Introduced in version 18.10.

ngramMinHash

Splits a ASCII string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

ngramMinHash(string[, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple

Examples

Usage example

SELECT ngramMinHash('RawTree') AS Tuple;
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,9054248444481805918) │
└────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashArg

Splits a ASCII string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHash function with the same input. It is case sensitive.

Syntax

ngramMinHashArg(string[, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum n-grams each. Tuple(String)

Examples

Usage example

SELECT ngramMinHashArg('RawTree') AS Tuple;
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('Hou','lic','ick','ous','ckH','Cli')) │
└───────────────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashArgCaseInsensitive

Splits a ASCII string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashCaseInsensitive function with the same input. It is case insensitive.

Syntax

ngramMinHashArgCaseInsensitive(string[, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum n-grams each. Tuple(Tuple(String))

Examples

Usage example

SELECT ngramMinHashArgCaseInsensitive('RawTree') AS Tuple;
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','kHo','use','Cli'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashArgCaseInsensitiveUTF8

Splits a UTF-8 string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashCaseInsensitiveUTF8 function with the same input. It is case insensitive.

Syntax

ngramMinHashArgCaseInsensitiveUTF8(string[, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum n-grams each. Tuple(Tuple(String))

Examples

Usage example

SELECT ngramMinHashArgCaseInsensitiveUTF8('RawTree') AS Tuple;
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ckH','ous','ick','lic','kHo','use'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashArgUTF8

Splits a UTF-8 string into n-grams of ngramsize symbols and returns the n-grams with minimum and maximum hashes, calculated by the ngramMinHashUTF8 function with the same input. It is case sensitive.

Syntax

ngramMinHashArgUTF8(string[, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum n-grams each. Tuple(Tuple(String))

Examples

Usage example

SELECT ngramMinHashArgUTF8('RawTree') AS Tuple;
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('kHo','Hou','lic','ick','ous','ckH')) │
└───────────────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashCaseInsensitive

Splits a ASCII string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

ngramMinHashCaseInsensitive(string[, ngramsize, hashnum])

Arguments

  • string — String. String. - ngramsize — The size of an n-gram. Optional. Possible values: any number from 1 to 25. Default value: 3. UInt8. - hashnum — The number of minimum and maximum hashes used to calculate the result. Optional. Possible values: any number from 1 to 25. Default value: 6. UInt8.

Returned value

Tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64). Tuple

Examples

Usage example

SELECT ngramMinHashCaseInsensitive('RawTree') AS Tuple;
┌─Tuple──────────────────────────────────────┐
│ (2106263556442004574,13203602793651726206) │
└────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashCaseInsensitiveUTF8

Splits a UTF-8 string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes.. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

ngramMinHashCaseInsensitiveUTF8(string [, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple

Examples

Usage example

SELECT ngramMinHashCaseInsensitiveUTF8('RawTree') AS Tuple;
┌─Tuple───────────────────────────────────────┐
│ (12493625717655877135,13203602793651726206) │
└─────────────────────────────────────────────┘

Introduced in version 21.1.

ngramMinHashUTF8

Splits a UTF-8 string into n-grams of ngramsize symbols and calculates hash values for each n-gram and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

ngramMinHashUTF8(string[, ngramsize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple

Examples

Usage example

SELECT ngramMinHashUTF8('RawTree') AS Tuple;
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,6742163577938632877) │
└────────────────────────────────────────────┘

Introduced in version 21.1.

ngramSimHash

Splits a ASCII string into n-grams of ngramsize symbols and returns the n-gram simhash.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

ngramSimHash(string[, ngramsize])

Arguments

  • string — String for which to compute the case sensitive simhash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is3. UInt8

Returned value

Returns the computed hash of the input string. UInt64

Examples

Usage example

SELECT ngramSimHash('RawTree') AS Hash;
┌───────Hash─┐
│ 1627567969 │
└────────────┘

Introduced in version 21.1.

ngramSimHashCaseInsensitive

Splits a ASCII string into n-grams of ngramsize symbols and returns the n-gram simhash. It is case insensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

ngramSimHashCaseInsensitive(string[, ngramsize])

Arguments

  • string — String for which to compute the case insensitive simhash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8

Returned value

Hash value. UInt64. UInt64

Examples

Usage example

SELECT ngramSimHashCaseInsensitive('RawTree') AS Hash;
┌──────Hash─┐
│ 562180645 │
└───────────┘

Introduced in version 21.1.

ngramSimHashCaseInsensitiveUTF8

Splits a UTF-8 string into n-grams of ngramsize symbols and returns the n-gram simhash. It is case insensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller is the Hamming Distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

ngramSimHashCaseInsensitiveUTF8(string[, ngramsize])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8

Returned value

Returns the computed hash value. UInt64

Examples

Usage example

SELECT ngramSimHashCaseInsensitiveUTF8('RawTree') AS Hash;
┌───────Hash─┐
│ 1636742693 │
└────────────┘

Introduced in version 21.1.

ngramSimHashUTF8

Splits a UTF-8 encoded string into n-grams of ngramsize symbols and returns the n-gram simhash. It is case sensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

ngramSimHashUTF8(string[, ngramsize])

Arguments

  • string — String for which to compute the hash. String
  • ngramsize — Optional. The size of an n-gram, any number from 1 to 25. The default value is 3. UInt8

Returned value

Returns the computed hash value. UInt64

Examples

Usage example

SELECT ngramSimHashUTF8('RawTree') AS Hash;
┌───────Hash─┐
│ 1628157797 │
└────────────┘

Introduced in version 21.1.

sipHash128

Like sipHash64 but produces a 128-bit hash value, i.e. the final xor-folding state is done up to 128 bits.

:::tip use sipHash128Reference for new projects This 128-bit variant differs from the reference implementation and is weaker. This version exists because, when it was written, there was no official 128-bit extension for SipHash. New projects are advised to use sipHash128Reference. :::

Syntax

sipHash128(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns a 128-bit SipHash hash value. FixedString(16)

Examples

Usage example

SELECT hex(sipHash128('foo', '\x01', 3));
┌─hex(sipHash128('foo', '', 3))────┐
│ 9DE516A64A414D4B1B609415E4523F24 │
└──────────────────────────────────┘

Introduced in version 1.1.

sipHash128Keyed

Same as sipHash128 but additionally takes an explicit key argument instead of using a fixed key.

:::tip use sipHash128ReferenceKeyed for new projects This 128-bit variant differs from the reference implementation and it's weaker. This version exists because, when it was written, there was no official 128-bit extension for SipHash. New projects should probably use sipHash128ReferenceKeyed. :::

Syntax

sipHash128Keyed((k0, k1), [arg1, arg2, ...])

Arguments

  • (k0, k1) — A tuple of two UInt64 values representing the key. Tuple(UInt64, UInt64)
  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

A 128-bit SipHash hash value of type FixedString(16). FixedString(16)

Examples

Usage example

SELECT hex(sipHash128Keyed((506097522914230528, 1084818905618843912),'foo', '\x01', 3));
┌─hex(sipHash128Keyed((506097522914230528, 1084818905618843912), 'foo', '', 3))─┐
│ B8467F65C8B4CFD9A5F8BD733917D9BF                                              │
└───────────────────────────────────────────────────────────────────────────────┘

Introduced in version 23.2.

sipHash128Reference

Like sipHash128 but implements the 128-bit algorithm from the original authors of SipHash.

Syntax

sipHash128Reference(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed 128-bit SipHash hash value of the input arguments. FixedString(16)

Examples

Usage example

SELECT hex(sipHash128Reference('foo', '', 3));
┌─hex(sipHash128Reference('foo', '', 3))─┐
│ 4D1BE1A22D7F5933C0873E1698426260       │
└────────────────────────────────────────┘

Introduced in version 23.2.

sipHash128ReferenceKeyed

Same as sipHash128Reference but additionally takes an explicit key argument instead of using a fixed key.

Syntax

sipHash128ReferenceKeyed((k0, k1), arg1[, arg2, ...])

Arguments

  • (k0, k1) — Tuple of two values representing the key Tuple(UInt64, UInt64)
  • arg1[, arg2, ...] — A variable number of input arguments for which to compute the hash. Any

Returned value

Returns the computed 128-bit SipHash hash value of the input arguments. FixedString(16)

Examples

Usage example

SELECT hex(sipHash128Reference('foo', '', 3));
┌─hex(sipHash128Reference('foo', '', 3))─┐
│ 4D1BE1A22D7F5933C0873E1698426260       │
└────────────────────────────────────────┘

Introduced in version 23.2.

sipHash64

Produces a 64-bit SipHash hash value.

This is a cryptographic hash function. It works at least three times faster than the MD5 hash function.

The function interprets all the input parameters as strings and calculates the hash value for each of them. It then combines the hashes using the following algorithm:

  1. The first and the second hash value are concatenated to an array which is hashed.
  2. The previously calculated hash value and the hash of the third input parameter are hashed in a similar way.
  3. This calculation is repeated for all remaining hash values of the original input.

:::note the calculated hash values may be equal for the same input values of different argument types. This affects for example integer types of different size, named and unnamed Tuple with the same data, Map and the corresponding Array(Tuple(key, value)) type with the same data. :::

Syntax

sipHash64(arg1[, arg2, ...])

Arguments

  • arg1[, arg2, ...] — A variable number of input arguments. Any

Returned value

Returns a computed hash value of the input arguments. UInt64

Examples

Usage example

SELECT sipHash64(array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type;
┌──────────────SipHash─┬─type───┐
│ 11400366955626497465 │ UInt64 │
└──────────────────────┴────────┘

Introduced in version 1.1.

sipHash64Keyed

Like sipHash64 but additionally takes an explicit key argument instead of using a fixed key.

Syntax

sipHash64Keyed((k0, k1), arg1[,arg2, ...])

Arguments

  • (k0, k1) — A tuple of two values representing the key. Tuple(UInt64, UInt64)
  • arg1[,arg2, ...] — A variable number of input arguments. Any

Returned value

Returns the computed hash of the input values. UInt64

Examples

Usage example

SELECT sipHash64Keyed((506097522914230528, 1084818905618843912), array('e','x','a'), 'mple', 10, toDateTime('2019-06-15 23:00:00')) AS SipHash, toTypeName(SipHash) AS type;
┌─────────────SipHash─┬─type───┐
│ 8017656310194184311 │ UInt64 │
└─────────────────────┴────────┘

Introduced in version 23.2.

wordShingleMinHash

Splits a ASCII string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

wordShingleMinHash(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64)

Examples

Usage example

SELECT wordShingleMinHash('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
┌─Tuple──────────────────────────────────────┐
│ (16452112859864147620,5844417301642981317) │
└────────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleMinHashArg

Splits a ASCII string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHash function with the same input. It is case sensitive.

Syntax

wordShingleMinHashArg(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String))

Examples

Usage example

SELECT wordShingleMinHashArg('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
┌─Tuple─────────────────────────────────────────────────────────────────┐
│ (('OLAP','database','analytical'),('online','oriented','processing')) │
└───────────────────────────────────────────────────────────────────────┘

Introduced in version 1.1.

wordShingleMinHashArgCaseInsensitive

Splits a ASCII string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHashCaseInsensitive function with the same input. It is case insensitive.

Syntax

wordShingleMinHashArgCaseInsensitive(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String))

Examples

Usage example

SELECT wordShingleMinHashArgCaseInsensitive('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
┌─Tuple──────────────────────────────────────────────────────────────────┐
│ (('queries','database','analytical'),('oriented','processing','DBMS')) │
└────────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleMinHashArgCaseInsensitiveUTF8

Splits a UTF-8 string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHashCaseInsensitiveUTF8 function with the same input. It is case insensitive.

Syntax

wordShingleMinHashArgCaseInsensitiveUTF8(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String))

Examples

Usage example

SELECT wordShingleMinHashArgCaseInsensitiveUTF8('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
┌─Tuple──────────────────────────────────────────────────────────────────┐
│ (('queries','database','analytical'),('oriented','processing','DBMS')) │
└────────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleMinHashArgUTF8

Splits a UTF-8 string into parts (shingles) of shinglesize words each and returns the shingles with minimum and maximum word hashes, calculated by the wordShingleMinHashUTF8 function with the same input. It is case sensitive.

Syntax

wordShingleMinHashArgUTF8(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two tuples with hashnum word shingles each. Tuple(Tuple(String))

Examples

Usage example

SELECT wordShingleMinHashArgUTF8('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).', 1, 3) AS Tuple;
┌─Tuple─────────────────────────────────────────────────────────────────┐
│ (('OLAP','database','analytical'),('online','oriented','processing')) │
└───────────────────────────────────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleMinHashCaseInsensitive

Splits a ASCII string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

wordShingleMinHashCaseInsensitive(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64)

Examples

Usage example

SELECT wordShingleMinHashCaseInsensitive('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
┌─Tuple─────────────────────────────────────┐
│ (3065874883688416519,1634050779997673240) │
└───────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleMinHashCaseInsensitiveUTF8

Splits a UTF-8 string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case insensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

wordShingleMinHashCaseInsensitiveUTF8(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64)

Examples

Usage example

SELECT wordShingleMinHashCaseInsensitiveUTF8('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
┌─Tuple─────────────────────────────────────┐
│ (3065874883688416519,1634050779997673240) │
└───────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleMinHashUTF8

Splits a UTF-8 string into parts (shingles) of shinglesize words, calculates hash values for each word shingle and returns a tuple with these hashes. Uses hashnum minimum hashes to calculate the minimum hash and hashnum maximum hashes to calculate the maximum hash. It is case sensitive.

Can be used to detect semi-duplicate strings with tupleHammingDistance. For two strings, if the returned hashes are the same for both strings, then those strings are the same.

Syntax

wordShingleMinHashUTF8(string[, shinglesize, hashnum])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8
  • hashnum — Optional. The number of minimum and maximum hashes used to calculate the result, any number from 1 to 25. The default value is 6. UInt8

Returned value

Returns a tuple with two hashes — the minimum and the maximum. Tuple(UInt64, UInt64)

Examples

Usage example

SELECT wordShingleMinHashUTF8('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Tuple;
┌─Tuple──────────────────────────────────────┐
│ (16452112859864147620,5844417301642981317) │
└────────────────────────────────────────────┘

Introduced in version 21.1.

wordShingleSimHash

Splits a ASCII string into parts (shingles) of shinglesize words and returns the word shingle simhash. Is is case sensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

wordShingleSimHash(string[, shinglesize])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8

Returned value

Returns the computed hash value. UInt64

Examples

Usage example

SELECT wordShingleSimHash('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
┌───────Hash─┐
│ 2328277067 │
└────────────┘

Introduced in version 21.1.

wordShingleSimHashCaseInsensitive

Splits a ASCII string into parts (shingles) of shinglesize words and returns the word shingle simhash. It is case insensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

wordShingleSimHashCaseInsensitive(string[, shinglesize])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8

Returned value

Returns the computed hash value. UInt64

Examples

Usage example

SELECT wordShingleSimHashCaseInsensitive('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
┌───────Hash─┐
│ 2194812424 │
└────────────┘

Introduced in version 21.1.

wordShingleSimHashCaseInsensitiveUTF8

Splits a UTF-8 encoded string into parts (shingles) of shinglesize words and returns the word shingle simhash. It is case insensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming Distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

wordShingleSimHashCaseInsensitiveUTF8(string[, shinglesize])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8

Returned value

Returns the computed hash value. UInt64

Examples

Usage example

SELECT wordShingleSimHashCaseInsensitiveUTF8('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
┌───────Hash─┐
│ 2194812424 │
└────────────┘

Introduced in version 1.1.

wordShingleSimHashUTF8

Splits a UTF-8 string into parts (shingles) of shinglesize words and returns the word shingle simhash. It is case sensitive.

Can be used for detection of semi-duplicate strings with bitHammingDistance. The smaller the Hamming distance of the calculated simhashes of two strings, the more likely these strings are the same.

Syntax

wordShingleSimHashUTF8(string[, shinglesize])

Arguments

  • string — String for which to compute the hash. String
  • shinglesize — Optional. The size of a word shingle, any number from 1 to 25. The default value is 3. UInt8

Returned value

Returns the computed hash value. UInt64

Examples

Usage example

SELECT wordShingleSimHashUTF8('RawTree® is a column-oriented database management system (DBMS) for online analytical processing of queries (OLAP).') AS Hash;
┌───────Hash─┐
│ 2328277067 │
└────────────┘

Introduced in version 21.1.

wyHash64

Computes a 64-bit wyHash64 hash value.

Syntax

wyHash64(arg)

Arguments

  • arg — String argument for which to compute the hash. String

Returned value

Returns the computed 64-bit hash value UInt64

Examples

Usage example

SELECT wyHash64('RawTree') AS Hash;
12336419557878201794

Introduced in version 22.7.

xxHash32

Calculates a xxHash from a string.

For the 64-bit version see xxHash64

Syntax

xxHash32(arg)

Arguments

  • arg — Input string to hash. String

Returned value

Returns the computed 32-bit hash of the input string. UInt32

Examples

Usage example

SELECT xxHash32('Hello, world!');
┌─xxHash32('Hello, world!')─┐
│                 834093149 │
└───────────────────────────┘

Introduced in version 20.1.

xxHash64

Calculates a xxHash from a string.

For the 32-bit version see xxHash32

Syntax

xxHash64(arg)

Arguments

  • arg — Input string to hash. String

Returned value

Returns the computed 64-bit hash of the input string. UInt64

Examples

Usage example

SELECT xxHash64('Hello, world!');
┌─xxHash64('Hello, world!')─┐
│      17691043854468224118 │
└───────────────────────────┘

Introduced in version 20.1.

xxh3

Computes a XXH3 64-bit hash value.

Syntax

xxh3(expr)

Arguments

  • expr — A list of expressions of any data type. Any

Returned value

Returns the computed 64-bit xxh3 hash value UInt64

Examples

Usage example

SELECT xxh3('RawTree')
18009318874338624809

Introduced in version 22.12.

xxh3_128

Computes a XXH3 128-bit hash value.

Syntax

xxh3_128(expr)

Arguments

  • expr — A list of expressions of any data type. Any

Returned value

Returns the computed 128-bit xxh3 hash value UInt128

Examples

Usage example

SELECT hex(xxh3_128('RawTree'))
3A038784C52804B4DBA43A038784C528

Introduced in version 26.2.