使用FileInputFormat.addInputPaths递归添加HDFS路径
我有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Eitan Illuz 提到的此处,在 Hadoop 2.4.0 中引入了
mapreduce.input.fileinputformat.input.dir.recursive
配置属性,当设置为true
时,指示输入格式以递归方式包含文件。在 Java 代码中,它看起来像这样:
我一直在使用这个新属性,发现它运行良好。
编辑:更好的是,在
FileInputFormat
上使用这个新方法可以达到相同的结果:As Eitan Illuz mentioned here, in Hadoop 2.4.0 a
mapreduce.input.fileinputformat.input.dir.recursive
configuration property was introduced that when set totrue
instructs the input format to include files recursively.In Java code it looks like this:
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:这是当前版本的 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.