1

I have a class Hello with a few methods

I would like to create a hello object within a UDF pyspark function, such as:

def foo_generation(query_params):
  query_obj = Hello()
  foo = query_obj.hello_method(query_params)
  return foo
​
spark.udf.register("foo_generation", foo_generation)
df = df.withColumn("foo", F.expr("foo_generation(query_param_ES)"))

This doesn't appear to be working. How should I generate a Hello object in this instance?

1 Answer 1

0
from pyspark.sql import SparkSession
from pyspark.sql.types import StringType
from pyspark.sql.functions import udf

@udf(returnType=StringType())
def foo_generation(str):
  query_obj = Hello()
  foo = query_obj.hello_method(str)
  return foo

df = df.withColumn("foo", F.expr("foo_generation(str)"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.