可以利用override map函数的第三个参数。map函数如下:
public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
String path = ((FileSplit) reporter.getInputSplit()).getPath().toString();
即可取得全路径。
下面这个方法可以做文件选取:
public class Filter implements PathFilter {
public boolean accept(Path path) {
return !(path.toString().indexOf("abc") > -1);
}
}
jobConf
.set(
"mapred.input.pathFilter.class"
,
"Filter"
);
org.apache.hadoop.fs
Interface PathFilter
-
All Known Implementing Classes:
- OutputLogFilter
public interface PathFilter
| Method Summary | |
|---|---|
boolean | accept(Path path) Tests whether or not the specified abstract pathname should be included in a pathname list. |
| Method Detail |
|---|
accept
boolean accept(Path path)
-
Tests whether or not the specified abstract pathname should be included in a pathname list.
-
Parameters:
-
path- The abstract pathname to be tested
Returns:
-
trueif and only ifpathnameshould be included
-
本文介绍如何在Hadoop中使用自定义的Filter类来过滤输入文件,通过实现PathFilter接口并重写accept方法,可以按需选择处理特定的文件路径。
1876

被折叠的 条评论
为什么被折叠?



