I am trying to create a simple working code in pyspark (Using Livy to access spark). I am using below link as reference. https://pylivy.readthedocs.io/en/latest/index.html
But it gives error says spark is not defined.
from livy import LivySession
LIVY_URL = "<Livy_URL>"
with LivySession.create(LIVY_URL) as session:
spark = SparkSession.builder.master("local").appName('file_filter').getOrCreate()
df=spark.read.option("header","true").option("inferSchema","true").csv("file_path")
#filter the rows with country = USA
session.run("filtered = df.filter(df.Country == 'USA')")
local_df = session.read("filtered")
local_df.write.format("csv").save("output_file_path")
Error
df=spark.read.option("header","true").option("inferSchema","true").csv("file_path")
NameError: name 'spark' is not defined
I think its not able to create the spark session.What change in the code is needed?