0
votes

I am not able to return flaot values after calculating average of numbers to output.collect..can anyone please help me??

public static class MapClass extends MapReduceBase implements 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);

}

}

public static class Reduce extends MapReduceBase implements 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));
}

}

1

1 Answers

2
votes

Are you using org.apache.hadoop.io.FloatWritable as your output Key or Value type (wherever you want to store the float in?

You'll need to amend the Generics signature to your mapper / reduce too (depending on where you're calculating the average, and also amend your job configuration to use FloatWritable as an output class type (again depends on whether you're using the float as an output key or value).

Post some code back into your question if you're still having problems