= hadoop programming 完全公式 = || || || 輸入 key || || 輸入 value|| || 輸出 Key || || 輸出 Value|| || || Mapper|| < || A || , || B || , || C || , || D || > || || map || ( || A || , || B || , || !OutputCollector < C , D > || , ||Reporter reporter || ) || || output|| . || collect || ( || c || , || d || ) || || || ||Reducer|| < || C || , || D || , || E || , ||F || > || || reduce|| ( || C || , || D || , || !OutputCollector < E , F > || , ||Reporter reporter || ) || || output|| . || collect || ( || e || , || f || ) || || * A, B, C, D ,E, F 分別代表可以用的類別;c, d, e, f 代表由C,D,E,F所產生的物件 * 有了這張表,我們規劃要寫M/R程式的時候: * 先把Map的輸入 應該屬於哪種類別的,則A,B定好 * Map的輸出定好,則 C,D也ok了 * 接下來想最終輸出的該為何類別,則 E,F 決定好 * 分別填入 ABCDEF之後,整個程式的架構就出來了,接下來就看你的程式如何實做 {{{ public static class Map extends MapReduceBase implements Mapper { public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) throws IOException { while (tokenizer.hasMoreTokens()) { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); output.collect(word, one); }}} {{{ public static class Reduce extends MapReduceBase implements Reducer { public void reduce(Text key, Iterator values,OutputCollector output, Reporter reporter) throws IOException { int sum = 0; while (values.hasNext()) { sum += values.next().get(); } output.collect(key, new IntWritable(sum)); }}}