Hash functions

**Arguments**

- `arg` — A string in UTF-16LE encoding. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the computed hash of the UTF-16LE encoded string. [`Int32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT javaHashUTF16LE(convertCharset('test', 'utf-8', 'utf-16le'));
```

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

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

Introduced in: v1.1.0

Calculates the [jump consistent hash](https://arxiv.org/pdf/1406.2294.pdf) for an integer.

**Syntax**

```
jumpConsistentHash(key, buckets)
```

**Arguments**

- `key` — The input key. [`UInt64`](/docs/sql-reference/data-types/int-uint)
- `buckets` — The number of buckets. [`Int32`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`Int32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT jumpConsistentHash(256, 4)
```

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

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

Introduced in: v23.4.0

Calculates the 32-bit [MurmurHash2](https://github.com/aappleby/smhasher) hash of the input value using the same seed as used by [Kafka](https://github.com/apache/kafka/blob/461c5cfe056db0951d9b74f5adc45973670404d7/clients/src/main/java/org/apache/kafka/common/utils/Utils.java#L482) and without the highest bit to be compatible with [Default Partitioner](https://github.com/apache/kafka/blob/139f7709bd3f5926901a21e55043388728ccca78/clients/src/main/java/org/apache/kafka/clients/producer/internals/BuiltInPartitioner.java#L328).

**Syntax**

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

**Arguments**

- `arg1[, arg2, ...]` — A variable number of parameters for which to compute the hash. [`Any`](/docs/sql-reference/data-types)

**Returned value**

Returns the calculated hash value of the input arguments. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**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 │
└────────────┴──────────┘
```

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

Introduced in: v25.4.0

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`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the 32-byte Keccak-256 hash of the input string as a fixed-length string. [`FixedString(32)`](/docs/sql-reference/data-types/fixedstring)

**Examples**

**Usage example**

```
SELECT hex(keccak256('hello'))
```

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

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

Introduced in: v22.6.0

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

**Syntax**

```
kostikConsistentHash(input, n)
```

**Aliases**: `yandexConsistentHash`

**Arguments**

- `input` — An integer key. [`UInt64`](/docs/sql-reference/data-types/int-uint)
- `n` — The number of buckets. [`UInt16`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns the computed hash value. [`UInt16`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT kostikConsistentHash(16045690984833335023, 2);
```

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

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

Introduced in: v1.1.0

Produces a 64-bit [MetroHash](http://www.jandrewrogers.com/2015/05/27/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`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed hash of the input arguments. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**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 │
└──────────────────────┴────────┘
```

## murmurHash2\_32[​](#murmurHash2_32 "Direct link to murmurHash2_32")

Introduced in: v18.5.0

Computes the [MurmurHash2](https://github.com/aappleby/smhasher) 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`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed hash value of the input arguments. [`UInt32`](/docs/sql-reference/data-types/int-uint)

**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 │
└─────────────┴────────┘
```

## murmurHash2\_64[​](#murmurHash2_64 "Direct link to murmurHash2_64")

Introduced in: v18.10.0

Computes the [MurmurHash2](https://github.com/aappleby/smhasher) 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`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed hash of the input arguments. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**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 │
└──────────────────────┴────────┘
```

## murmurHash3\_128[​](#murmurHash3_128 "Direct link to murmurHash3_128")

Introduced in: v18.10.0

Computes the 128-bit [MurmurHash3](https://github.com/aappleby/smhasher) 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`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed 128-bit `MurmurHash3` hash value of the input arguments. [`FixedString(16)`](/docs/sql-reference/data-types/fixedstring)

**Examples**

**Usage example**

```
SELECT hex(murmurHash3_128('foo', 'foo', 'foo'));
```