【发布时间】:2018-02-02 17:26:31
【问题描述】:
我正在尝试对两个数据帧中的每一行应用 pyspark sql 函数哈希算法来识别差异。哈希算法基于字符串,所以我试图将字符串以外的任何数据类型转换为字符串。我在日期列转换中遇到了大部分问题,因为在转换为字符串之前需要更改日期格式以使其与基于哈希的匹配保持一致。请帮助我解决这个问题。
#Identify the fields which are not strings
from pyspark.sql.types import *
fields = df_db1.schema.fields
nonStringFields = map(lambda f: col(f.name), filter(lambda f: not isinstance(f.dataType, StringType), fields))
#Convert the date fields to specific date format and convert to string.
DateFields = map(lambda f: col(f.name), filter(lambda f: isistance(f.dataType, DateType), fields))
#convert all other fields other than string to string.
【问题讨论】:
标签: python-3.x apache-spark pyspark spark-dataframe pyspark-sql