1 回答

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
合并器必須能夠接受來自映射器的數(shù)據(jù),并且必須輸出可用作化簡(jiǎn)器輸入的數(shù)據(jù)。在本例中,“合并器”輸出類型為 ,但“化簡(jiǎn)器”輸入類型為 ,因此它們不匹配。<Text, Text><Text, IntWritable>
對(duì)于這個(gè)問題,您實(shí)際上并不需要MapReduce,因?yàn)槟诿織l線上都有每年的所有可用數(shù)據(jù),并且您不需要在行之間進(jìn)行比較。
String line = value.toString();
String[] elements = line.split("\\s");
Text year = new Text(elements[0]);
int maxTemp = INTEGER.MIN_VALUE;
int minTemp = INTEGER.MAX_VALUE;
int temp;
for(int i = 1; i<elements.length;i++) {
temp = Integer.parseInt(elements[i])
if (temp < minTemp) {
minTemp = temp;
} else if (temp > maxTemp) {
maxTemp = temp;
}
}
System.out.println("For year " + year + ", the minimum temperature was " + minTemp + " and the maximum temperature was " + maxTemp);
添加回答
舉報(bào)