hadoop programming 0715
- 整理出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 | ) |
|
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> 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<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values,OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
output.collect(key, new IntWritable(sum));