Pyspark error with UDF: py4j.Py4JException: Method __getnewargs__([]) does not exist error

微笑、不失礼 提交于 2019-12-11 03:25:51

问题


I am trying to solve the following error (I am using the databricks platform and spark 2.0)

tweets_cleaned.createOrReplaceTempView("tweets_cleanedSQL")
def Occ(keyword):
  occurences = spark.sql("SELECT * \
                                FROM tweets_cleanedSQL \
                                WHERE LOWER(text) LIKE '%" + keyword + "%' \
                            ")
  return occurences.count()


occurences_udf = udf(Occ)

If I run this code, I receive the following error:

py4j.Py4JException: Method getnewargs([]) does not exist ==> error only occurs when trying to define the udf.


回答1:


the UDF function turns a regular function to a function that is applied on any element of the input column. You cannot have this function call spark functions (in this case you are calling spark.sql which would in turn need to create workers etc. which is not supported.



来源:https://stackoverflow.com/questions/40848824/pyspark-error-with-udf-py4j-py4jexception-method-getnewargs-does-not-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!