【发布时间】:2020-11-13 03:52:07
【问题描述】:
我是 Spark 的新手。我正在尝试从pyspark.sql 创建一个 Spark 会话以加载 .csv 文件。但是,每次我尝试执行第二行(如下所示)时,该命令都会持续执行数小时,并且似乎永远不会生成其他代码行。
代码如下:
from pyspark.sql import SparkSession
sp = SparkSession.builder.appName("solution").config("spark.some.config.option", "some-value").getOrCreate()
df = sp.read.csv('walmart_stock.csv', header= True, inferSchema= True)
df.columns
另外,如果我等了半天杀掉内核,就会出现如下异常:
<ipython-input-23-16c3797ce83f> in <module>
----> 1 sp = SparkSession.builder.appName("solution").config("spark.some.config.option", "some-value").getOrCreate()
~\anaconda3\lib\site-packages\pyspark\sql\session.py in getOrCreate(self)
184 sparkConf.set(key, value)
185 # This SparkContext may be an existing one.
--> 186 sc = SparkContext.getOrCreate(sparkConf)
187 # Do not update `SparkConf` for existing `SparkContext`, as it's shared
188 # by all sessions.
~\anaconda3\lib\site-packages\pyspark\context.py in getOrCreate(cls, conf)
369 with SparkContext._lock:
370 if SparkContext._active_spark_context is None:
--> 371 SparkContext(conf=conf or SparkConf())
372 return SparkContext._active_spark_context
373
~\anaconda3\lib\site-packages\pyspark\context.py in __init__(self, master, appName, sparkHome, pyFiles, environment, batchSize, serializer, conf, gateway, jsc, profiler_cls)
126 " is not allowed as it is a security risk.")
127
--> 128 SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
129 try:
130 self._do_init(master, appName, sparkHome, pyFiles, environment, batchSize, serializer,
~\anaconda3\lib\site-packages\pyspark\context.py in _ensure_initialized(cls, instance, gateway, conf)
318 with SparkContext._lock:
319 if not SparkContext._gateway:
--> 320 SparkContext._gateway = gateway or launch_gateway(conf)
321 SparkContext._jvm = SparkContext._gateway.jvm
322
~\anaconda3\lib\site-packages\pyspark\java_gateway.py in launch_gateway(conf, popen_kwargs)
100 # Wait for the file to appear, or for the process to exit, whichever happens first.
101 while not proc.poll() and not os.path.isfile(conn_info_file):
--> 102 time.sleep(0.1)
103
104 if not os.path.isfile(conn_info_file):
您能否提出问题所在?
【问题讨论】:
-
sp = SparkSession.builder.appName("solution").getOrCreate()有效吗?您似乎传递了无效的配置参数。 -
您是否从某处复制粘贴了这一行?您希望这样做: .config("spark.some.config.option", "some-value") ?
-
我正在尝试通过创建一个简单的 sparksession 来读取 .csv 文件。但是一旦我执行此代码,笔记本就会被挂起。我在网上查看了许多参考资料,但找不到错误。此外,没有配置部分的命令,即“ sp = SparkSession.builder.appName("solution").getOrCreate() ”不起作用。我也试过了。
标签: python apache-spark pyspark jupyter-notebook