使用FileInputFormat.addInputPaths递归添加HDFS路径

发布于 2024-12-15 10:13:58 字数 511 浏览 2 评论 0原文

我有一个 HDFS 结构,类似于

a/b/file1.gz
a/b/file2.gz
a/c/file3.gz
a/c/file4.gz

我使用经典模式

FileInputFormat.addInputPaths(conf, args[0]);

来设置 java map reduce 作业的输入路径。

如果我将 args[0] 指定为 a/b,则效果很好,但如果我仅指定 a,则它会失败(我的目的是处理所有4 个文件)

错误是

Exception in thread "main" java.io.IOException: Not a file: hdfs://host:9000/user/hadoop/a

如何递归添加 a 下的所有内容?

我一定错过了一些简单的东西......

I've got a HDFS structure something like

a/b/file1.gz
a/b/file2.gz
a/c/file3.gz
a/c/file4.gz

I'm using the classic pattern of

FileInputFormat.addInputPaths(conf, args[0]);

to set my input path for a java map reduce job.

This works fine if I specify args[0] as a/b but it fails if I specify just a (my intention being to process all 4 files)

the error being

Exception in thread "main" java.io.IOException: Not a file: hdfs://host:9000/user/hadoop/a

How do I recursively add everything under a ?

I must be missing something simple...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好听的两个字的网名 2024-12-22 10:13:58

正如 Eitan Illuz 提到的此处,在 Hadoop 2.4.0 中引入了 mapreduce.input.fileinputformat.input.dir.recursive 配置属性,当设置为 true 时,指示输入格式以递归方式包含文件。

在 Java 代码中,它看起来像这样:

Configuration conf = new Configuration();
conf.setBoolean("mapreduce.input.fileinputformat.input.dir.recursive", true);
Job job = Job.getInstance(conf);
// etc.

我一直在使用这个新属性,发现它运行良好。

编辑:更好的是,在 FileInputFormat 上使用这个新方法可以达到相同的结果:

Job job = Job.getInstance();
FileInputFormat.setInputDirRecursive(job, true);

As Eitan Illuz mentioned here, in Hadoop 2.4.0 a mapreduce.input.fileinputformat.input.dir.recursive configuration property was introduced that when set to true instructs the input format to include files recursively.

In Java code it looks like this:

Configuration conf = new Configuration();
conf.setBoolean("mapreduce.input.fileinputformat.input.dir.recursive", true);
Job job = Job.getInstance(conf);
// etc.

I've been using this new property and find that it works well.

EDIT: Better yet, use this new method on FileInputFormat that achieves the same result:

Job job = Job.getInstance();
FileInputFormat.setInputDirRecursive(job, true);
浅听莫相离 2024-12-22 10:13:58

这是当前版本的 Hadoop 中的一个错误。这是相同的 JIRA 。仍处于打开状态。要么在代码中进行更改并构建二进制文件,要么等待在即将发布的版本中修复它。可以打开/关闭文件的递归处理,请检查 JIRA 附带的补丁以了解更多详细信息。

This is a bug in the current version of Hadoop. Here is the JIRA for the same. It's still in open state. Either make the changes in the code and build the binaries or wait for it to be fixed in the coming releases. Processing of the files recursively can be turned on/off, check the patch attached to the JIRA for more details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文