2016-10-13 5 views
0
package com.ibm.dw61; 

import java.io.IOException; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Reducer; 

public class MaxTempReducer extends 
    Reducer<Text, IntWritable, Text, IntWritable> { 

    public void reduce(Text key, Iterable<IntWritable> values, Context context) 
       throws IOException, InterruptedException { 
     int maxTemp = Integer.MIN_VALUE; 
     for (IntWritable value: values) { 
     maxTemp = Math.max(maxTemp, value.get()); 
     } 
     context.write(key, new IntWritable(maxTemp)); 

    } 
} 

質問:最大月刊温度リデューサーコード

1)int型maxTemp =はInteger.MIN_VALUE < -----この行はmaxTemp変数の初期化のようです。なぜコーダーはゼロに初期化しないのですか? Integer.MIN_VALUEには-2147483648が与えられます。最低気温が-100度に達することは不可能です。

2)context.write(key、new IntWritable(maxTemp)< ------これは最終結果です。キーは月、maxTempはその月の最高気温です。キー(月)のためにmaxTempために必要はありません?

答えて