开发者学堂课程【Hadoop 企业优化及扩展案例:多 Job 串联案例第一个 Job】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/96/detail/1573
多 Job 串联案例第一个 Job
目录:
一、编写 OneIndexMapper 类
二、写 Mapper 方法
三、写 Reduce 方法
四、驱动
1. 编写 OneIndexMapper 类
public class OneIndexMapper extends Mapper(String name;
@Override
protected void setup(Mapper Context context)
throws I0Exception, InterruptedException f
//获取文件名称FileSplit inputSplit = (FileSplit) context. getInputSplit();name=inputSplit. getPath() . getName();
@Override
protected void map(LongWritable key, Text value, Mapper . Context context)
throws I0Exception, InterruptedException
{
2.写 Mapper 方法
protected void map(LongWritable key, Text value, Mapper .Context context)
throws I0Exception, InterruptedException f
//
atguigu pingping
// 1获取一行String line = value . toStrin
g();
//2切割String[] fields = line.split(" ");
//写出for(String word : fields)
{
k.set(word+"--"+name);
context.write(k, v);
}
3.写 Reduce 方法
public class OneIndexReducer extends Reducerf
IntWritable V = new IntWritable();
@0verride
protected void reduce(Text key, Iterable values,
Context context) throws I0Exception, InterruptedException
{
int sum= 0;
//1累加求和for (IntWritable value : values)
{
sum += value.get();
v.set(sum);
//写出context .write(key, v);
}
4.驱动