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



如何为映射reduce指定通用输入路径。

文件夹结构示例为:

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

有许多日期文件夹和许多天文件夹。

我想深入到特定范围的日期文件夹文件夹,然后选择特定范围的数据文件。如果我尝试

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

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

如果您提供

'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; 
    }
}

像这样注册PathFilter-

FileInputFormat.setInputPathFilter(job, CustomPathFilter.class);

相关内容

最新更新