如何在新的hadoopapi中递归地使用目录结构?

g0czyy6m  于 2021-06-02  发布在  Hadoop
关注(0)|答案(2)|浏览(437)

我的文件结构如下:

/indir/somedir1/somefile
/indir/somedir1/someotherfile...
/indir/somedir2/somefile
/indir/somedir2/someotherfile...

现在,我想将所有内容递归地传递到mr作业中,并且我正在使用新的api。所以我做了:

FileInputFormat.setInputPaths(job, new Path("/indir"));

但是工作失败了:

Error: java.io.FileNotFoundException: Path is not a file: /indir/somedir1

我使用的是hadoop2.4,在本文中,hadoop2的新api不支持递归文件。但我想知道这是怎么回事,因为我认为在hadoop作业中抛出一个大型嵌套目录结构是世界上最普通的事情。。。
那么,这是有意的,还是一个bug?在这两方面,除了使用旧的api,还有其他解决方法吗?

4ngedf3f

4ngedf3f1#

另一种配置方法是通过 FileInputFormat 班级。

FileInputFormat.setInputDirRecursive(job, true);
hfsqlsce

hfsqlsce2#

我自己找到了答案。在上述论坛帖子中链接的jira中,有两条关于如何做对的评论:
mapreduce.input.fileinputformat.input.dir.recursivetrue (注解状态) mapred.input.dir.recursive 但这是不赞成的)
使用 FileInputFormat.addInputPath 指定输入目录
有了这些变化,它就工作了。

相关问题