dev_xulongjin b2f5b0e40b feat(hbase-lesson): 添加新模块 hbase-20250509
- 新增 hbase-20250509 模块用于 HBase 课程项目
- 实现了流量统计和词频统计两个 MapReduce 任务
- 添加了相应的 Mapper、Reducer 和 Driver 类- 创建了输入样例文件- 配置了 Maven 依赖
2025-05-12 09:07:29 +08:00

30 lines
821 B
Java

package WordCount;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
public class WordCountReducer extends Reducer<Text, IntWritable,Text,IntWritable> {
/**
* 一个单词 一组 执行一次
* b
* d 两组
* 执行两次
* 单词 b <1,1,1,1,1,1,1,1,1>
* @param key
* @param values
* @param context
* @throws IOException
* @throws InterruptedException
*/
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int number = 0 ;
for (IntWritable value : values) { //
number++ ;
}
context.write(key ,new IntWritable(number));
}
}