hash(*exprs: Expression, seed: Any | None = None, hash_function: Literal['xxhash', 'xxhash32', 'xxhash64', 'xxhash3_64', 'murmurhash3', 'sha1'] | None = 'xxhash') -> Expression
Hashes the values in the Expression.
Uses the specified hash function to hash the values in the expression. Default to XXH3_64bits non-cryptographic hash function.
Parameters:
| Name | Type | Description | Default |
exprs | Expression | One or more expressions (or column names/wildcards) to hash. | () |
seed | optional | Seed used for generating the hash. Defaults to 0. | None |
hash_function | optional | Hash function to use. One of "xxhash" (alias for "xxhash3_64"), "xxhash32", "xxhash64", "xxhash3_64", "murmurhash3", or "sha1". Defaults to "xxhash" (alias for "xxhash3_64"). | 'xxhash' |
Returns:
| Name | Type | Description |
Expression | UInt64 Expression | |
Note
Null values will produce a hash value instead of being propagated as null.
Source code in daft/functions/misc.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367 | def hash(
*exprs: Expression,
seed: Any | None = None,
hash_function: Literal["xxhash", "xxhash32", "xxhash64", "xxhash3_64", "murmurhash3", "sha1"] | None = "xxhash",
) -> Expression:
"""Hashes the values in the Expression.
Uses the specified hash function to hash the values in the expression. Default to [XXH3_64bits](https://xxhash.com/) non-cryptographic hash function.
Args:
exprs: One or more expressions (or column names/wildcards) to hash.
seed (optional): Seed used for generating the hash. Defaults to 0.
hash_function (optional): Hash function to use. One of "xxhash" (alias for "xxhash3_64"), "xxhash32", "xxhash64", "xxhash3_64", "murmurhash3", or "sha1". Defaults to "xxhash" (alias for "xxhash3_64").
Returns:
Expression (UInt64 Expression): The hashed expression.
Note:
Null values will produce a hash value instead of being propagated as null.
"""
# Only pass hash_function if explicitly provided to maintain backward compatibility in string representation
kwargs = {}
if not exprs:
raise ValueError("hash() requires at least one expression")
normalized = []
for expr in exprs:
if isinstance(expr, str):
resolved = col(expr)
normalized.append(resolved)
else:
resolved = Expression._to_expression(expr)
normalized.append(resolved)
if seed is not None:
kwargs["seed"] = seed
if hash_function is not None:
kwargs["hash_function"] = hash_function
return Expression._call_builtin_scalar_fn("hash", *normalized, **kwargs)
|