Spark 迭代 HDFS 目录 [英] Spark iterate HDFS directory

查看:37
本文介绍了Spark 迭代 HDFS 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 HDFS 上有一个目录目录,我想遍历这些目录.有没有什么简单的方法可以使用 SparkContext 对象对 Spark 执行此操作?

I have a directory of directories on HDFS, and I want to iterate over the directories. Is there any easy way to do this with Spark using the SparkContext object?

推荐答案

您可以使用 org.apache.hadoop.fs.FileSystem.具体来说,FileSystem.listFiles([path], true)

还有 Spark...

And with Spark...

FileSystem.get(sc.hadoopConfiguration).listFiles(..., true)

编辑

值得注意的是,最好的做法是获取与 Path 的方案关联的 FileSystem.

It's worth noting that good practice is to get the FileSystem that is associated with the Path's scheme.

path.getFileSystem(sc.hadoopConfiguration).listFiles(path, true)

这篇关于Spark 迭代 HDFS 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆