我想在通过 SparkContext 加载它们之前检查 hdfs 中是否存在多个文件。
我使用 pyspark。我试过
os.system("hadoop fs -test -e %s"%path)
但是由于我有很多路径要检查,所以作业崩溃了。
我还尝试了 sc.wholeTextFiles(parent_path)
然后按键过滤。但它也崩溃了,因为 parent_path 包含很多子路径和文件。
你可以帮帮我吗?
最佳答案
正确的说法Tristan Reid :
...(Spark) It can read many formats, and it supports Hadoop glob expressions, which are terribly useful for reading from multiple paths in HDFS, but it doesn't have a builtin facility that I'm aware of for traversing directories or files, nor does it have utilities specific to interacting with Hadoop or HDFS.
无论如何,这是他对相关问题的回答:Pyspark: get list of files/directories on HDFS path
一旦你有了目录中的文件列表,就很容易检查特定文件是否存在。
希望对你有所帮助。
关于hadoop - pyspark : how to check if a file exists in hdfs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32334772/