Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/docs/source/reference/pyspark.sql/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ Hash Functions
sha
sha1
sha2
xxh3_128
xxh3_64
xxhash64


Expand Down
14 changes: 14 additions & 0 deletions python/pyspark/sql/connect/functions/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4674,6 +4674,20 @@ def md5(col: "ColumnOrName") -> Column:
md5.__doc__ = pysparkfuncs.md5.__doc__


def xxh3_64(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("xxh3_64", col)


xxh3_64.__doc__ = pysparkfuncs.xxh3_64.__doc__


def xxh3_128(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("xxh3_128", col)


xxh3_128.__doc__ = pysparkfuncs.xxh3_128.__doc__


def sha1(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("sha1", col)

Expand Down
2 changes: 2 additions & 0 deletions python/pyspark/sql/functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@
"sha",
"sha1",
"sha2",
"xxh3_128",
"xxh3_64",
"xxhash64",
# Collection Functions
"aggregate",
Expand Down
65 changes: 65 additions & 0 deletions python/pyspark/sql/functions/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14697,6 +14697,71 @@ def md5(col: "ColumnOrName") -> Column:
return _invoke_function_over_columns("md5", col)


@_try_remote_functions
def xxh3_64(col: "ColumnOrName") -> Column:
"""Returns a 64-bit hash value of the argument using the XXH3 algorithm.

Unlike :func:`xxhash64`, which hashes one or more columns structurally, this hashes the raw
bytes of a single value with seed 0, so its result is byte compatible with the reference XXH3.

.. versionadded:: 4.3.0

Parameters
----------
col : :class:`~pyspark.sql.Column` or column name
target column to compute on. A column of string or binary type.

Returns
-------
:class:`~pyspark.sql.Column`
Returns a column that evaluates to a long.

See Also
--------
:meth:`pyspark.sql.functions.xxh3_128`
:meth:`pyspark.sql.functions.xxhash64`

Examples
--------
>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([('Spark',)], ['a'])
>>> df.select(sf.xxh3_64('a').alias('h')).collect()
[Row(h=80997306238743657)]
"""
return _invoke_function_over_columns("xxh3_64", col)


@_try_remote_functions
def xxh3_128(col: "ColumnOrName") -> Column:
"""Returns a 128-bit XXH3 hash of the argument as a 32-character hex string.

.. versionadded:: 4.3.0

Parameters
----------
col : :class:`~pyspark.sql.Column` or column name
target column to compute on. A column of string or binary type.

Returns
-------
:class:`~pyspark.sql.Column`
Returns a column that evaluates to a string.

See Also
--------
:meth:`pyspark.sql.functions.xxh3_64`
:meth:`pyspark.sql.functions.md5`

Examples
--------
>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([('Spark',)], ['a'])
>>> df.select(sf.xxh3_128('a').alias('h')).collect()
[Row(h='7d57dd84c60c86ca1f4e82ab91a12b5e')]
"""
return _invoke_function_over_columns("xxh3_128", col)


@_try_remote_functions
def sha1(col: "ColumnOrName") -> Column:
"""Returns the hex string result of SHA-1.
Expand Down
24 changes: 24 additions & 0 deletions sql/api/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6551,6 +6551,30 @@ object functions {
@scala.annotation.varargs
def xxhash64(cols: Column*): Column = Column.fn("xxhash64", cols: _*)

/**
* Returns a 64-bit hash value of the argument using the XXH3 algorithm.
*
* @param col
* the column to hash. A column of string or binary type.
* @group hash_funcs
* @since 4.3.0
* @return
* Returns a column that evaluates to a long.
*/
def xxh3_64(col: Column): Column = Column.fn("xxh3_64", col)

/**
* Returns a 128-bit XXH3 hash of the argument as a 32-character hex string.
*
* @param col
* the column to hash. A column of string or binary type.
* @group hash_funcs
* @since 4.3.0
* @return
* Returns a column that evaluates to a string.
*/
def xxh3_128(col: Column): Column = Column.fn("xxh3_128", col)

/**
* Returns null if the condition is true, and throws an exception otherwise.
*
Expand Down
Loading