【发布时间】:2019-10-11 14:00:52
【问题描述】:
我有一个 PySpark UDF,它返回一个字符串元组,我已将其编码为一个结构。这是一个玩具示例,
def my_func(x):
return "1", x, "3"
spark.udf.register("my_func", lambda x: my_func(x), StructType([StructField("one", StringType(),
StructField("two", StringType(),
StructField("three", StringType()])
我称之为
spark.sql("select col1, my_func(col1) from sdf").show()
与返回元组的一个元素相比,返回整个元组的性能提高了 10 到 20 倍,例如
spark.udf.register("my_func", lambda x: my_func(x)[1], StringType())
这是一个已知问题吗?有没有办法避免转换速度变慢?
【问题讨论】:
标签: apache-spark pyspark