Hash functions

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

**Returned value**

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

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

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

Introduced in: v1.1.0

[Interprets](/docs/sql-reference/functions/type-conversion-functions#reinterpretAsString) 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](/docs/sql-reference/data-types/int-uint) in big-endian byte order. The function is
relatively slow (5 million short strings per second per processor core).

Consider using the [`sipHash64`](#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`](/docs/sql-reference/data-types)

**Returned value**

Returns the computed half MD5 hash of the given input params returned as a `UInt64` in big-endian byte order. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT HEX(halfMD5('abc', 'cde', 'fgh'));
```

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

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

Introduced in: v20.1.0

Calculates a "HiveHash" from a string.
This is just [`JavaHash`](#javaHash) with zeroed out sign bits.
This function is used in [Apache Hive](https://en.wikipedia.org/wiki/Apache_Hive) for versions before 3.0.

Note

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

**Returned value**

Returns the computed "hive hash" of the input string. [`Int32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT hiveHash('Hello, world!');
```

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

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

Introduced in: v25.5.0

Implements the logic of the iceberg [hashing transform](https://iceberg.apache.org/spec/#appendix-b-32-bit-hash-requirements)

**Syntax**

```
icebergHash(value)
```

**Arguments**

- `value` — Source value to take the hash of [`Integer`](/docs/sql-reference/data-types/int-uint) or [`Bool`](/docs/sql-reference/data-types/boolean) or [`Decimal`](/docs/sql-reference/data-types/decimal) or [`Float*`](/docs/sql-reference/data-types/float) or [`String`](/docs/sql-reference/data-types/string) or [`FixedString`](/docs/sql-reference/data-types/fixedstring) or [`UUID`](/docs/sql-reference/data-types/uuid) or [`Date`](/docs/sql-reference/data-types/date) or [`Time`](/docs/sql-reference/data-types/time) or [`DateTime`](/docs/sql-reference/data-types/datetime)

**Returned value**

Returns a 32-bit Murmur3 hash, x86 variant, seeded with 0 [`Int32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Example**

```
SELECT icebergHash(1.0 :: Float32)
```

```
-142385009
```

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

Introduced in: v1.1.0

Calculates a 32-bit hash of an integer.

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

**Syntax**

```
intHash32(arg)
```

**Arguments**

- `arg` — Integer to hash. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns the computed 32-bit hash code of the input integer [`UInt32`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT intHash32(42);
```

```
┌─intHash32(42)─┐
│    1228623923 │
└───────────────┘
```

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

Introduced in: v1.1.0

Calculates a 64-bit hash of an integer.

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

**Syntax**

```
intHash64(int)
```

**Arguments**

- `int` — Integer to hash. [`(U)Int*`](/docs/sql-reference/data-types/int-uint)

**Returned value**

64-bit hash code. [`UInt64`](/docs/sql-reference/data-types/int-uint)

**Examples**

**Usage example**

```
SELECT intHash64(42);
```

```
┌────────intHash64(42)─┐
│ 11490350930367293593 │
└──────────────────────┘
```

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

Introduced in: v20.1.0

Calculates JavaHash from:

- [string](http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/String.java#l1452),
- [Byte](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Byte.java#l405),
- [Short](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Short.java#l410),
- [Integer](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Integer.java#l959),
- [Long](https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/Long.java#l1060).

Note

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 ClickHouse types.

**Syntax**

```
javaHash(arg)
```

**Arguments**

- `arg` — Input value to hash. [`Any`](/docs/sql-reference/data-types)

**Returned value**

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

**Examples**

**Usage example 1**

```
SELECT javaHash(toInt32(123));
```

```
┌─javaHash(toInt32(123))─┐
│               123      │
└────────────────────────┘
```

**Usage example 2**

```
SELECT javaHash('Hello, world!');
```

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

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

Introduced in: v20.1.0

Calculates [JavaHash](http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/478a4add975b/src/share/classes/java/lang/String.java#l1452) 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`](/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**