[SPARK-45900][SQL][PYTHON] Add xxh3_64 and xxh3_128 functions - #57690
Open
SreeramaYeshwanthGowd wants to merge 1 commit into
Open
[SPARK-45900][SQL][PYTHON] Add xxh3_64 and xxh3_128 functions#57690SreeramaYeshwanthGowd wants to merge 1 commit into
SreeramaYeshwanthGowd wants to merge 1 commit into
Conversation
uros-b
reviewed
Jul 31, 2026
| return hash128Hex(input, 0L); | ||
| } | ||
|
|
||
| /** Returns the XXH3 128-bit hash as a 32-character lowercase hex string (canonical big-endian). */ |
Member
There was a problem hiding this comment.
This seems like > 100 chars, please fix to avoid lint issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Add two built in scalar SQL functions that hash their argument with the XXH3 algorithm:
xxh3_64(expr)returns a 64-bit hash as aBIGINT.xxh3_128(expr)returns a 128-bit hash as a 32-character lowercase hexSTRING.API surface added:
xxh3_64,xxh3_128functions.xxh3_64(col),functions.xxh3_128(col)pyspark.sql.functions.xxh3_64/xxh3_128Implementation notes:
XXH3Java class ports the XXH3 64-bit and 128-bit hashes from the reference implementation (github.com/Cyan4973/xxHash, perdoc/xxhash_spec.md). It is a self contained port with no new dependency, mirroring the existingXXH64helper.hash.scalaand follow themd5/crc32pattern: single argument, input implicitly cast toBinaryType,nullIntolerant, withxxh3_64returningLongType(likecrc32) andxxh3_128returning a hex string (likemd5).Why are the changes needed?
Spark's existing
xxhash64returns 64 bits, which collides too often for large scale surrogate keys or deterministic sampling (a birthday collision becomes likely in the billions of rows). XXH3 is the modern successor to XXH64:xxh3_128provides a collision resistant 128-bit digest, andxxh3_64is a faster 64-bit alternative. This is a natural extension of the existing hash function family (md5,crc32,xxhash64).Design decisions (worth an explicit review, as this is a permanent public API):
xxh128sum). This differs fromxxhash64, which is a variadic, structural hash with an internal seed (not reference compatible). The 128-bit result is the canonical XXH3 hex; the 64-bit result is the two's complement view of the unsigned XXH3 value, so its hex matches the reference while the signed decimal representation may differ.xxhash3(expr, bits)function, because a Spark expression needs a statically known result type.xxh3_128returns a hexSTRING(likemd5), matching the reference tool's canonical hex output, rather than rawBINARY. A seeded variant could be added as a follow up.Does this PR introduce any user-facing change?
Yes. It adds two new built in SQL functions and their Scala and PySpark DataFrame API entries. No existing behavior changes.
How was this patch tested?
XXH3Suitevalidates the port against the reference implementation's known-answer vectors, covering every length branch (0, 1-3, 4-8, 9-16, 17-128, 129-240, and the long path) and block boundaries with both a zero and a non-zero seed, for both the 64-bit and 128-bit outputs.HashExpressionsSuitechecks the expressions' values, null handling, and interpreted vs codegen consistency.misc-functions.sql(string and binary input, and null propagation), and regeneratedsql-expression-schema.md.Was this patch authored or co-authored using generative AI tooling? No