2013-08-05 145 views
1

如何爲我的地圖縮放指定通用輸入路徑。hadoop輸入路徑指定文件夾範圍

示例文件夾結構是:

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

有許多日期的文件夾和多天的文件夾。

我想在日期文件夾文件夾的特定範圍內向下鑽取,然後選取特定範圍的數據文件。如果我嘗試

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

這將讀取所有文件。我想指定日期範圍,即讀取13-06-01和13-06-25內的所有文件,並忽略所有其他日期文件夾。我怎麼做?

回答

0

如果您提供

'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); 
+0

塔卡納我用在輸入文件路徑的正則表達式來指定一個範圍? – user2441441

+0

@ user2441441:例如:如果您使用'folderA/folderB/folderC/mainfolder/*/*',則所有文件都將被視爲匹配/ */*,並且當您在PathFilter中通過自定義日期範圍進行篩選時,只有特定的文件纔會被處理。如果你正在尋找別的東西,請回復。謝謝! –