MapReduce---chain链条式操作

本文通过实例解析MapReduce的chain链条式操作,包括Mapper1切割单词、Mapper2去除'of'、Mapper2_2过滤'tom'开头的单词,以及Mapper3对输出进行次数统计并排除出现次数少于1次的单词。
摘要由CSDN通过智能技术生成

准备数据:

hello world of tom1
hello world of tom1
hello world of tom2
hello world of tom3
hello world of tom3
hello world of tom4
hello world of tom4

思路分析图:

1、Mapper1(切割单词)

2、Mapper2 (滤掉单词中of)

3、Mapper2_2(滤掉单词中带tom的)

4、Mapper3(reduce的输出是Mapper3的输入,滤掉单次数量少于1=次的)


1、Mapper1(切割单词)

package hadoop.mr.chain;

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;

/**
 *
 */
public class Mapper1 extends Mapper<LongWritable,Text,Text,IntWritable>{
	protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
		System.out.println("map1 : " + value.toString());
		String line = value.toString();
		String[] arr =  line.split(" ");
		for(String w : arr){
			context.write(new Text(w),new IntWritable(1));
		}
	}
}


2、Mapper2 (滤掉单词中of)

package hadoop.mr.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值