hadoop输入路径指定文件夹范围

k97glaaz  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(426)

如何为map reduce指定通用输入路径。
文件夹结构示例如下:

folderA/folderB/folderC/mainfolder/date/day/data files

有许多日期文件夹和许多天文件夹。
我想深入到一个特定范围的日期文件夹文件夹,然后拿起特定范围的数据文件。如果我尝试

'folderA/folderB/folderC/mainfolder/*/*'

这将读取所有文件。我想为文件夹指定一个日期范围,即读取13-06-01和13-06-25中的所有文件,并忽略所有其他日期文件夹。我该怎么做?

vjhs03f7

vjhs03f71#

如果你提供

'folderA/folderB/folderC/mainfolder/*/*'

作为一个输入,如果要过滤掉特定的路径,您可能需要创建一个自定义的pathfilter
在fileinputformat中有这个函数-

static void setInputPathFilter (JobConf conf, Class<? extends PathFilter> filter)
Info: Set a PathFilter to be applied to the input paths for the map-reduce job

例如。

public static class CustomPathFilter implements PathFilter {
    @Override
    public boolean accept(Path path) {
        //you can implement your logic for finding the valid range of paths here.
        //The valid range of dates and days for directories and files can be input 
        //as arguments to the job.
        //Return true if you find a match or else return false.
        return false; 
    }
}

像这样注册路径过滤器-

FileInputFormat.setInputPathFilter(job, CustomPathFilter.class);

相关问题