【发布时间】:2019-09-10 22:13:32
【问题描述】:
我有 hdfs 目录中的文件列表,我想从 hdfs 目录迭代 pyspark 中的文件并将每个文件存储在一个变量中并使用该变量进行进一步处理。我在下面遇到错误..
py4j.protocol.Py4JError: An error occurred while calling z:org.apache.spark.api.python.PythonUtils.toSeq. Trace:
py4j.Py4JException: Method toSeq([class org.apache.hadoop.fs.Path]) does not exist
InputDir = "/Data/Ready/ARRAY_COUNTERS"#输入hdfs目录
hadoop = sc._jvm.org.apache.hadoop
fs = hadoop.fs.FileSystem
conf = hadoop.conf.Configuration()
path = hadoop.fs.Path(InputDir)
for f in fs.get(conf).listStatus(path):
Filename = f.getPath()
df = spark.read.csv(Filename,header=True)
#I am getting above error in while reading this file.
【问题讨论】:
-
你可以尝试使用 as Filename = str(f.getPath())
标签: pyspark