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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425 | 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)
|