gpt4 book ai didi

python - pyspark:找不到本地文件

转载 作者:可可西里 更新时间:2023-11-01 16:30:39 25 4
gpt4 key购买 nike

我有以下简单的 python 代码:

from __future__ import print_function

import sys
from operator import add

from pyspark import SparkContext


if __name__ == "__main__":
print(len(sys.argv))
if len(sys.argv) < 2:
print("Usage: wordcount <file>", file=sys.stderr)
exit(-1)
sc = SparkContext(appName="PythonWordCount")
lines = sc.textFile(sys.argv[2], 1)
counts = lines.flatMap(lambda x: x.split(' ')).map(lambda x: (x, 1)).reduceByKey(add)
output = counts.collect()
for (word, count) in output:
print("%s: %i" % (word, count))

sc.stop()

然后我尝试通过执行以下操作在本地集群上运行它:

spark-submit --master spark://rws-lnx-sprk01:7077 /home/edamameQ/wordcount.py wordcount /home/edamameQ/wordTest.txt

wordTest.txt 绝对可用:

edamameQ@spark-cluster:~$ ls
data jars myJob.txt wordTest.txt wordcount.py

但我不断收到错误:

Driver stacktrace:
at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1283)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1271)
at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1270)
at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
:
:
Caused by: java.io.FileNotFoundException: File file:/home/edamameQ/wordTest.txt does not exist
at org.apache.hadoop.fs.RawLocalFileSystem.getFileStatus(RawLocalFileSystem.java:520)
at org.apache.hadoop.fs.FilterFileSystem.getFileStatus(FilterFileSystem.java:398)
at org.apache.hadoop.fs.ChecksumFileSystem$ChecksumFSInputChecker.<init>(ChecksumFileSystem.java:137)
at org.apache.hadoop.fs.ChecksumFileSystem.open(ChecksumFileSystem.java:339)

相同的代码在 AWS 上使用来自 s3 位置的输入文件。为了在本地集群上运行,我需要调整什么吗?谢谢!

最佳答案

您要阅读的文件必须可供所有工作人员访问。如果这是一个本地文件,唯一的选择是为每台工作机器保留一份副本。

关于python - pyspark:找不到本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34051598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com