public static class Map extends MapReduceBase implements Mapper
MapReduceBase
类、Mapper
接口和JobConf
类已经在Hadoop 0.20.203中被弃用。
现在应该使用什么?
编辑1 - 对于Mapper
和MapReduceBase
,我们只需要继承Mapper
就可以了。
public static class Map extends Mapper
<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
编辑2 - 对于JobConf
,我们应该使用以下配置:
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf);
job.setMapperClass(WordCount.Map.class);
}
编辑3 - 我找到了一篇介绍新API的好教程:http://sonerbalkir.blogspot.com/2010/01/new-hadoop-api-020x.html