大数据全系列 教程
1869个小节阅读:467.5k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
package com.itbaizhan;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
public class WeatherReducer extends Reducer<Weather, Text,Text, NullWritable> {
@Override
protected void reduce(Weather key, Iterable<Text> values, Reducer<Weather, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {
/**2019-10-01 19:21:02 38c
* 2019-10-01 14:21:02 37c
2019-10-02 14:01:02 36c
2019-10-03 14:01:02 35c
*/
//定义一个变量
int day = -1;
//遍历values
for(Text value:values){
if(day==-1){
//说明这是当前年月下的温度最高的第一条数据,将之直接输出
context.write(value,NullWritable.get());
//将当前条数据的天获取出来赋值给day变量
day = key.getDay();
}else{
if(day!=key.getDay()){//当前条数据的天不等于上一次输出的天时,才会输出。
context.write(value,NullWritable.get());
//已经输出了当前年月下温度最高的两天数据,该组数据结束。
break;
}
}
}
}
}