Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
Returns the hex string result of SHA-2 family of hash functions (SHA-224, SHA-256, SHA-384, and SHA-512). The numBits indicates the desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256). Supports Spark Connect.
For the corresponding Databricks SQL function, see sha2 function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.sha2(col=<col>, numBits=<numBits>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Target column to compute on. |
numBits |
int |
The desired bit length of the result, which must have a value of 224, 256, 384, 512, or 0 (which is equivalent to 256). |
Returns
pyspark.sql.Column: the column for computed results.
Examples
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([['Alice'], ['Bob']], ['name'])
df.select('*', dbf.sha2('name', 256)).show(truncate=False)
+-----+----------------------------------------------------------------+
|name |sha2(name, 256) |
+-----+----------------------------------------------------------------+
|Alice|3bc51062973c458d5a6f2d8d64a023246354ad7e064b1e4e009ec8a0699a3043|
|Bob |cd9fb1e148ccd8442e5aa74904cc73bf6fb54d1d54d333bd596aa9bb4bb4e961|
+-----+----------------------------------------------------------------+