我有一个python函数,例如:
def blank_as_null(x): return when(col(x) != "", col(x)).otherwise(None)
我使用这个函数时没有运行 udf(blank_as_null, StringType()) 如文件所示: http://spark.apache.org/docs/2.2.0/api/python/pyspark.sql.html 或在此视频中: https://youtu.be/AsW0QzbYVow?t=42m33s (在42:33你可以看到调用 udf (功能)
udf(blank_as_null, StringType())
udf
myData.withColumn('myColumn', blank_as_null('myColumn'))
先注册python函数有什么好处吗?在什么条件下注册是有益的?什么时候没关系?或者注册是在引擎盖下自动完成的?
我认为您混合了两种不同的转换:PySpark API转换和UDF:
when
otherwise
由于性能原因,您应该始终以第一种类型的转换为目标,但是如果您尝试使用sparkapi实现的转换不可行,那么您只能选择udf。