Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your mapper maps your inputs to the value that you want to take the average of. So let's say that your input is a text file formatted like</p> <pre><code>ProcessName Time process1 10 process2 20 . . . </code></pre> <p>Then you would need to take each line in your file, split it, grab the second column, and output the value of that column as an <code>IntWritable</code> (or some other <code>Writable</code> numeric type). Since you want to take the average of all times, not grouped by process name or anything, you will have a single fixed key. Thus, your mapper would look something like</p> <pre><code>private IntWritable one = new IntWritable(1); private IntWritable output = new IntWritable(); proctected void map(LongWritable key, Text value, Context context) { String[] fields = value.split("\t"); output.set(Integer.parseInt(fields[1])); context.write(one, output); } </code></pre> <p>Your reducer takes these values, and simply computes the average. This would look something like</p> <pre><code>IntWritable one = new IntWritable(1); DoubleWritable average = new DoubleWritable(); protected void reduce(IntWritable key, Iterable&lt;IntWrtiable&gt; values, Context context) { int sum = 0; int count = 0; for(IntWritable value : values) { sum += value.get(); count++; } average.set(sum / (double) count); context.Write(key, average); } </code></pre> <p>I'm making a lot of assumptions here, about your input format and what not, but they are reasonable assumptions and you should be able to adapt this to suit your exact needs.</p> <blockquote> <p>Will my output always be a text file or is it possible to directly store the average in some sort of a variable?</p> </blockquote> <p>You have a couple of options here. You can post-process the output of the job (written a single file), or, since you're computing a single value, you can store the result in a counter, for example.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload