Hash functions

```
SELECT ngramMinHashArgCaseInsensitive('ClickHouse') AS Tuple;
```

```
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','kHo','use','Cli'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

## ngramMinHashArgCaseInsensitiveUTF8[​](#ngramMinHashArgCaseInsensitiveUTF8 "Direct link to ngramMinHashArgCaseInsensitiveUTF8")

Introduced in: v21.1.0

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`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `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`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(Tuple(String))`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashArgCaseInsensitiveUTF8('ClickHouse') AS Tuple;
```

```
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ckH','ous','ick','lic','kHo','use'),('kHo','lic','ick','ous','ckH','Hou')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

## ngramMinHashArgUTF8[​](#ngramMinHashArgUTF8 "Direct link to ngramMinHashArgUTF8")

Introduced in: v21.1.0

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`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `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`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two tuples with `hashnum` n-grams each. [`Tuple(Tuple(String))`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashArgUTF8('ClickHouse') AS Tuple;
```

```
┌─Tuple─────────────────────────────────────────────────────────────────────────┐
│ (('ous','ick','lic','Hou','kHo','use'),('kHo','Hou','lic','ick','ous','ckH')) │
└───────────────────────────────────────────────────────────────────────────────┘
```

## ngramMinHashCaseInsensitive[​](#ngramMinHashCaseInsensitive "Direct link to ngramMinHashCaseInsensitive")

Introduced in: v21.1.0

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`](/docs/sql-reference/functions/tuple-functions#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](/docs/sql-reference/data-types/string). - `ngramsize` — The size of an n-gram. Optional. Possible values: any number from `1` to `25`. Default value: `3`. [UInt8](/docs/sql-reference/data-types/int-uint). - `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](/docs/sql-reference/data-types/int-uint).

**Returned value**

Tuple with two hashes — the minimum and the maximum. [Tuple](/docs/sql-reference/data-types/tuple)([UInt64](/docs/sql-reference/data-types/int-uint), [UInt64](/docs/sql-reference/data-types/int-uint)). [`Tuple`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashCaseInsensitive('ClickHouse') AS Tuple;
```

```
┌─Tuple──────────────────────────────────────┐
│ (2106263556442004574,13203602793651726206) │
└────────────────────────────────────────────┘
```

## ngramMinHashCaseInsensitiveUTF8[​](#ngramMinHashCaseInsensitiveUTF8 "Direct link to ngramMinHashCaseInsensitiveUTF8")

Introduced in: v21.1.0

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`](/docs/sql-reference/functions/tuple-functions#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`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `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`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashCaseInsensitiveUTF8('ClickHouse') AS Tuple;
```

```
┌─Tuple───────────────────────────────────────┐
│ (12493625717655877135,13203602793651726206) │
└─────────────────────────────────────────────┘
```

## ngramMinHashUTF8[​](#ngramMinHashUTF8 "Direct link to ngramMinHashUTF8")

Introduced in: v21.1.0

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`](/docs/sql-reference/functions/tuple-functions#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`](/docs/sql-reference/data-types/string)
- `ngramsize` — Optional. The size of an n-gram, any number from `1` to `25`. The default value is `3`. [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `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`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple with two hashes — the minimum and the maximum. [`Tuple`](/docs/sql-reference/data-types/tuple)

**Examples**

**Usage example**

```
SELECT ngramMinHashUTF8('ClickHouse') AS Tuple;
```

```
┌─Tuple──────────────────────────────────────┐
│ (18333312859352735453,6742163577938632877) │
└────────────────────────────────────────────┘
```

## ngramSimHash[​](#ngramSimHash "Direct link to ngramSimHash")

Introduced in: v21.1.0