【超详细】InteillJ JAVA运行MapReduce程序

MapReduce【开发】

需求:统计一堆文件中单词出现的个数。

Driver函数的流程:

  1. 获取配置信息,获取job对象实例
  2. 指定本程序jar包所在的本地路径
  3. 指定mapper,reducer业务类
  4. 指定mapper输出数据的kv类型
  5. 指定最终输出的数据的kv类型
  6. 指定job的输入原始文件所在的目录
  7. 指定job的输出粗结果所在的目录
  8. 提交作业

a. 环境搭建(WordCount入门例子)

  1. 创建一个maven工程
  2. Mapper模板
package edu.durant.hadoop;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//KIN,VIN,KOUT,VOUT
public class wordcntMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
   
    Text k = new Text();
    IntWritable v = new IntWritable(1);
    @Override
    protected  void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
   
        String line = value.toString();
        String[] words = line.split(" ");
        for (String word : words) {
   
            k.set(word);
            context.write(k,v);
        }
    }

}

注意:Map的<>内前两个参数必须是LongWritable, Text,这是系统定义的。

  1. Reducer模板

   public class IntSumReducer<Key> extends Reducer
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值