我正在研究 hadoop 1.2.1 的字数统计示例。但一定有什么改变了,因为我似乎无法让它发挥作用。
这是我的减少类:
public static class Reduce extends Reducer<WritableComparable, Writable, WritableComparable, Writable> {
public void reduce(WritableComparable key,
Iterator<Writable> values,
OutputCollector<WritableComparable, NullWritable> output,
Reporter reporter) throws IOException {
output.collect(key, NullWritable.get());
}
}
我的主要功能:
public static void main(String[] args) throws Exception {
JobConf jobConf = new JobConf(MapDemo.class);
jobConf.setNumMapTasks(10);
jobConf.setNumReduceTasks(1);
jobConf.setJobName("MapDemo");
jobConf.setOutputKeyClass(Text.class);
jobConf.setOutputValueClass(NullWritable.class);
jobConf.setMapperClass(Map.class);
jobConf.setReducerClass(Reduce.class);
jobConf.setInputFormat(TextInputFormat.class);
jobConf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(jobConf, new Path(args[0]));
FileOutputFormat.setOutputPath(jobConf, new Path(args[1]));
JobClient.runJob(jobConf);
}
我的 IDE 告诉我有一个错误,由 Maven 证实:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] com/example/mapreduce/MapDemo.java:[71,16] method setReducerClass in class org.apache.hadoop.mapred.JobConf cannot be applied to given types;
required: java.lang.Class<? extends org.apache.hadoop.mapred.Reducer>
found: java.lang.Class<com.example.mapreduce.MapDemo.Reduce>
reason: actual argument java.lang.Class<com.example.mapreduce.MapDemo.Reduce> cannot be converted to java.lang.Class<? extends org.apache.hadoop.mapred.Reducer> by method invocation conversion
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.679s
[INFO] Finished at: Mon Sep 16 09:23:08 PDT 2013
[INFO] Final Memory: 17M/202M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project inventory: Compilation failure
[ERROR] com/example/mapreduce/MapDemo.java:[71,16] method setReducerClass in class org.apache.hadoop.mapred.JobConf cannot be applied to given types;
[ERROR] required: java.lang.Class<? extends org.apache.hadoop.mapred.Reducer>
[ERROR] found: java.lang.Class<com.example.mapreduce.MapDemo.Reduce>
我相信在线字数统计示例对于 1.2.1 来说已经过时了。我该如何解决?有没有人有一个工作的 1.2.1 字数 java 源的链接?