Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 628
Yoren Van Couwenberghe Avatar asked Oct 14 '25 15:10

Yoren Van Couwenberghe


1 Answers

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.

like image 141
Assaf Mendelson Avatar answered Oct 17 '25 06:10

Assaf Mendelson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!