大数据技术之Hadoop之MapReduce(3)——CombineTextInputFormat

本文介绍了如何使用Hadoop的CombineTextInputFormat进行大数据处理的实战案例,通过一个统计单词数量的例子,详细展示了Mapper、Reducer和Driver类的实现,并解释了在处理多个小文件时如何利用CombineTextInputFormat提高效率。
摘要由CSDN通过智能技术生成
3.1.5 CombineTextInputFormat案例实操
示例:统计单词个数
  1. 准备工作
    在hdfs的根目录下创建input文件夹,然后在里面放置4个大小分别为1.5M、35M、5.5M、6.5M的小文件作为输入数据
  2. 具体代码
  • Mapper类
/**
 * @Author zhangyong
 * @Date 2020/3/4 16:35
 * @Version 1.0
 */
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
   
    private Text mapOutputKey = new Text();
    private IntWritable mapOutputValue = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
   
        String linevalue = value.toString();  //1.将读取的文件变成,偏移量+内容//读取一行数据
        StringTokenizer st = new StringTokenizer(linevalue);//使用空格分隔
        while (st.hasMoreTokens()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值