我正在研究hadoop1.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 word count java源代码吗?
2条答案
按热度按时间mw3dktmi1#
这行代码表明您正在混合hadoop的mapred和mapreduceapi版本。
使用mapred或mapreduce api。
am46iovg2#
你遵循了哪个环节?我从没见过这种厕所。但是您所遵循的方法肯定是过时的,因为它使用的是旧的api。我怀疑你是否正确地遵循了它。
这应该起作用:
要做的观察很少:
您没有发出任何计数,因为我可以看到nullwriteable从您的reducer发出。它只会发出键而不进行任何计数。
为输入和输出键/值使用适当的类型。
使用新的api。它更干净更好。