我有一个返回字符串列表的udf。这应该不会太难。我在执行udf时传入了数据类型,因为它返回一个字符串数组:ArrayType(StringType)。
现在,不知何故,这不起作用:
我正在操作的数据帧是df_subsets_concat,如下所示:
df_subsets_concat.show(3,False)+----------------------+
|col1 |
+----------------------+
|oculunt |
|predistposed |
|incredulous |
+----------------------+
only showing top 3 rows代码是
from pyspark.sql.types import ArrayType, FloatType, StringType
my_udf = lambda domain: ['s','n']
label_udf = udf(my_udf, ArrayType(StringType))
df_subsets_concat_with_md = df_subsets_concat.withColumn('subset', label_udf(df_subsets_concat.col1))结果就是
/usr/lib/spark/python/pyspark/sql/types.py in __init__(self, elementType, containsNull)
288 False
289 """
--> 290 assert isinstance(elementType, DataType), "elementType should be DataType"
291 self.elementType = elementType
292 self.containsNull = containsNull
AssertionError: elementType should be DataType我的理解是这是做这件事的正确方法。以下是一些资源:pySpark Data Frames "assert isinstance(dataType, DataType), "dataType should be DataType" How to return a "Tuple type" in a UDF in PySpark?
但是这两个都不能帮助我解决为什么它不工作的问题。我使用的是pyspark 1.6.1。
如何在pyspark中创建一个返回字符串数组的udf?
https://stackoverflow.com/questions/47682927
复制相似问题