Sam*_*uel 2 apache-spark apache-spark-sql pyspark
我目前正在使用 SparkSession,并被告知 SparkContext 位于 SparkSession 内。但是,在编写代码时,它向我显示 SparkSession 中不存在 SparkContext 的错误
下面是我所做的代码
import findspark
findspark.init()
from pyspark.sql import SparkSession, Row
import collections
spark = SparkSession.builder.config("spark.sql.warehouse.dir", "file://C:/temp").appName("SparkSQL").getOrCreate()
lines = spark.textFile('C:/Users/file.xslx')
Run Code Online (Sandbox Code Playgroud)
错误如下:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_59944/722806425.py in <module>
----> 1 lines = spark.textFile('C:/Users/samue/bt4221_spark/exercise/week5/customer-orders.xslx')
AttributeError: 'SparkSession' object has no attribute 'textFile'
Run Code Online (Sandbox Code Playgroud)
我当前的findspark版本:1.4.2 pyspark:3.0.3
我认为这与任何版本问题无关。任何帮助是极大的赞赏!:)
textFile
出现在SparkContext
课堂上而不是出现在SparkSession
。
spark.sparkContext.textFile('filepath')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3002 次 |
最近记录: |