【发布时间】:2018-10-15 18:43:41
【问题描述】:
我正在一个类中创建一个火花 UDF。当我执行下面的代码时,我得到了异常。
class A(B):
def __init__(self,spark):
B.__init__(self)
self.spark = spark
def process(self, df):
df = df.withColumn("col_sub_entry", self.conditions_title("entry_title"))
def conditions_entry_title(self,x:StringType()):
if len(x.split(" ") < 3):
return 0
else :
return x
conditions_title = udf(conditions_entry_title, IntegerType())
【问题讨论】:
-
能贴出整个类的实现吗?至少 udf 是如何实现的?我不认为您在此处定义
udf的方式是类中的有效语法。 -
我做过,检查一次
-
当我在课外使用 UDF 时它对我有用。
-
是的,您必须记住 pyspark 工作节点没有在驱动程序上创建类实例。他们那里只有基本的python方法。
标签: python pyspark user-defined-functions