title: Hadoop MapReducer string and math operations as output - error
body: <p>I am building mapreducer application which takes .txt with random numbers as input and i want to receive an output information like this:</p>
  <p>Max number: xx
  Arithmetic avg: xx
  Geometric avg: xx
  median: xx</p>
  <p>My Code:</p>
  <pre><code>import java.io.IOException;
  import java.util.StringTokenizer;
  import java.util.*;
  
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.io.IntWritable;
  import org.apache.hadoop.io.Text;
  import org.apache.hadoop.mapreduce.Job;
  import org.apache.hadoop.mapreduce.Mapper;
  import org.apache.hadoop.mapreduce.Reducer;
  import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  
  public class NumCount {
  
    public static class TokenizerMapper
         extends Mapper&lt;Object, Text, Text, IntWritable&gt;{
  
      private final static IntWritable one = new IntWritable(1);
      private Text number = new Text();
      
  
      public void map(Object key, Text value, Context context
                      ) throws IOException, InterruptedException {
        StringTokenizer itr = new StringTokenizer(value.toString());
        while (itr.hasMoreTokens()) {
          number.set(itr.nextToken());
          context.write(number, one);
        }
      }
    }
  
    public static class IntSumReducer
         extends Reducer&lt;Text,IntWritable,Text,IntWritable&gt; {
      private IntWritable result = new IntWritable();
  
      public void reduce(Text key, Iterable&lt;IntWritable&gt; values,
                         Context context
                         ) throws IOException, InterruptedException {
  
        List&lt;Integer&gt; numList = new ArrayList&lt;Integer&gt;();
  
        for (IntWritable val : values) {
           numList.add(val.get());
        }
      
        // Max number from file
        int maxNumber = Collections.max(numList,null);
  
        // Arithmetic average
        float sum = 0;
        for (int i : numList)
          sum += i;
  
        float arithmeticAverage = sum / numList.size();
  
        // Geometric average
        sum = 1;
        for (int i : numList)
          sum *= i;
        
        double geometricAverage = Math.pow(sum, (float)1/numList.size());
  
        // Median
  
        float median;
        
        if (numList.size() % 2 == 0)
           median = (float)(numList.get(numList.size()/2) + numList.get(numList.size()/2 - 1))/2;
        else
           median = numList.get(numList.size()/2);
  
        String summary = &quot;Max number: &quot; + maxNumber + &quot;\nArithmetic avg: &quot; + arithmeticAverage + &quot;\nGeometric avg: &quot; + geometricAverage + &quot;\nMedian&quot; + median;
  
        result.set(summary);
        context.write(key, result);
      }
    }
  
    public static void main(String[] args) throws Exception {
      Configuration conf = new Configuration();
      Job job = Job.getInstance(conf, &quot;number count&quot;);
      job.setJarByClass(NumCount.class);
      job.setMapperClass(TokenizerMapper.class);
      job.setCombinerClass(IntSumReducer.class);
      job.setReducerClass(IntSumReducer.class);
      job.setOutputKeyClass(Text.class);
      job.setOutputValueClass(IntWritable.class);
      FileInputFormat.addInputPath(job, new Path(args[0]));
      FileOutputFormat.setOutputPath(job, new Path(args[1]));
      System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
  }
  </code></pre>
  <p>The problem with my code is, i am getting error that i can't put string into IntWritable (looks logic, but how I can parse string value to output?)</p>
  <pre><code>result.set(summary);
  </code></pre>
  <p>What is more, when i tried to do something like this:</p>
  <pre><code>result.set(median);
  </code></pre>
  <p>I didn't receive median value, instead I received bad output, which was the list of numbers from input file with &quot;1&quot; nearby.</p>
  <p>I am totally green to hadoop and I don't have any clue how to do this right, any sugestions? ;x</p>