@Override public void map(String line, Pipe<CountRec> out) { StringTokenizer tokenizer = new StringTokenizer(line); while (tokenizer.hasMoreTokens()) { outrec.word = tokenizer.nextToken(); outrec.count = 1; out.put(outrec); } }
@Override public void map(String in, Pipe<CountRec> out) { StringTokenizer tokenizer = new StringTokenizer(in); CountRec rec = new CountRec(); while (tokenizer.hasMoreTokens()) { rec.word = tokenizer.nextToken(); rec.count = 1; out.put(rec); } }
@Override public void reduce(Pipe<CountRec> in, Pipe<Protos.CountRec> out) { String word = null; int count = 0; for (CountRec rec : in) { if (word == null) word = rec.word; count += rec.count; } out.put(Protos.CountRec.newBuilder().setWord(word).setCount(count).build()); }