Exemplo n.º 1
0
  @Override
  protected void map(Text key, StringTuple value, final Context context)
      throws IOException, InterruptedException {
    HashMap<String, Long> wordCount = new HashMap<String, Long>();
    for (String word : value.getEntries()) {
      if (wordCount.containsKey(word)) {
        wordCount.put(word, wordCount.get(word) + 1);
      } else {
        wordCount.put(word, (long) 1);
      }
    }

    for (Entry<String, Long> entry : wordCount.entrySet()) {
      try {
        context.write(new Text(entry.getKey()), new LongWritable(entry.getValue()));
      } catch (IOException e) {
        context.getCounter("Exception", "Output IO Exception").increment(1);
      } catch (InterruptedException e) {
        context.getCounter("Exception", "Interrupted Exception").increment(1);
      }
    }
  }