Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2025 09:20 PM
Hi team,
I believe you cannot create or access a SparkSession or run Spark operations like spark.sql() directly inside a Python UDF. input_table is a table argument, not a string with a table name. You receive it as a pandas DataFrame when using RETURNS TABLE
You need to define your logic outside SQL in a notebook and use regular Spark APIs:
def process_table(table_name): df = spark.table(table_name)
# Transform using Spark DataFrame APIs
df = df.withColumn("new_col", df["existing_col"]+2)
df.write.mode("overwrite").saveAsTable("processed_table")Then call process_table("my_table") in your notebook or job. Hope this helps!