【发布时间】:2021-03-09 00:37:06
【问题描述】:
我正在尝试在整个行的 pyspark 中使用 md5 函数计算哈希值。在 pyspark 数据框中,我为几列提供了多种复杂的数据类型。
for e.g : col: array (nullable = true)
| |-- element: struct (containsNull = true)
for e.g : col: array (nullable = true)
| |-- element: array (containsNull = true)
当我尝试计算整行的 md5 时,md5 会抛出错误并显示以下消息:
**`col`' is of array<array<string>> type. argument 28 requires (array<string> or string) type, however, '`col`' is of array<array<string>> type**
计算md5的代码:
def prepare_data_md5(data):
""" Prepare the data with md5 column.
:param data: input DataFrame object
:return: output DataFrame object
"""
return data.withColumn("hash", md5(concat_ws(*data.columns)))
1.是否有其他函数可以用于散列并且也适用于复杂的数据类型? 2. pyspark 或 python 中是否有一些库可用于展平复杂的数据类型,以便我可以在展平的数据帧上计算 md5?
【问题讨论】: