使用Livy创建Spark会话以处理文件:Anaconda Spyder

时间:2020-05-30 19:55:23

标签: apache-spark pyspark livy

我正在尝试在pyspark中创建一个简单的工作代码(使用Livy访问spark)。我正在使用以下链接作为参考。 https://pylivy.readthedocs.io/en/latest/index.html

但是它给出了错误,表明未定义火花。

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")

错误

    df=spark.read.option("header","true").option("inferSchema","true").csv("file_path")
NameError: name 'spark' is not defined

我认为它无法创建spark会话。需要对代码进行哪些更改?

0 个答案:

没有答案
相关问题