Skip to content

uuid

laktory.spark.functions.uuid ยค

uuid()

Create a unique id for each row.

RETURNS DESCRIPTION
Column

Output column

Examples:

import laktory  # noqa: F401
import pyspark.sql.functions as F

df = spark.range(3)
df = df.withColumn("uuid", F.laktory.uuid())
'''
+---+--------------------+
| id|                uuid|
+---+--------------------+
|  0|acc0b53e-a36f-4f8...|
|  1|56cdeb41-6828-486...|
|  2|64a7d2bf-5e1d-41a...|
+---+--------------------+
'''
Source code in laktory/spark/functions/string.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def uuid() -> Column:
    """
    Create a unique id for each row.

    Returns
    -------
    :
        Output column

    Examples
    --------
    ```py
    import laktory  # noqa: F401
    import pyspark.sql.functions as F

    df = spark.range(3)
    df = df.withColumn("uuid", F.laktory.uuid())
    '''
    +---+--------------------+
    | id|                uuid|
    +---+--------------------+
    |  0|acc0b53e-a36f-4f8...|
    |  1|56cdeb41-6828-486...|
    |  2|64a7d2bf-5e1d-41a...|
    +---+--------------------+
    '''
    ```
    """
    return F.expr("uuid()")