在计算输出的平均值后,我无法返回浮点值。收集..有人可以帮我吗?
公共静态类 MapClass 扩展 MapReduceBase 实现 Mapper {
private Text word = new Text();
public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
String line = value.toString();
String num = Integer.parseInt(num);
IntWritable one = new IntWritable(num);
word.set(“key”);
output.collect(word, one);
}
}
公共静态类 Reduce 扩展 MapReduceBase 实现 Reducer {
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output,
Reporter reporter) throws IOException {
int sum = 0;
int count=0;
int avg=0;
while (values.hasNext()) {
sum += values.next().get();
count++;
}
avg=sum/count;
output.collect(key, new IntWritable(avg));
}
}