开发者学堂课程【Hadoop 企业优化及扩展案例:多 Job 串联案例完成】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/96/detail/1574
多 Job 串联案例完成
目录:
一.写 TwolndexMapper.
二.将 mapper 写入 reducer
三.驱动
1. 写 TwolndexMapper.
protected void map( LongWritable key, Text value, Mapper .Cont
ext
context)
throws I0Exception, InterruptedException
{
atguigu--a.txt
atguigu--b.txt
atguigu--c.txt
// 1获取一行String line = value.toString();
// 2切割String[] fields = line.split("--");
// 3封装Text
k
= new Text();
Text
v
= new Text();
// 3写出context.write(key, value);
2. 将 mapper 写入 reducer
public class TwoIndexReducer extends Reducer
@0verride
protected void reduce(Text key,Iterable values, Context context)
throws I0Exception, InterruptedException f
atguigu --a.txt 3
--b.txt 2
--c.txt 2
atguigu c.txt-->2
b.txt-->2
a.txt-->3
// 1拼接字符串StringBuffer sb = new StringBuffer();
for (Text value : values)
{
sb. append(value.toString().replace("
\
t","-->") +"
\
t");
v.set(sb.toString());
// 2写出context.write(key, v);
}
3. 驱动