mapreduce 顺序组合
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class Driver {
public static class TokenizerMapper extends
Mapper<Object, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
}
public static class IntSumReducer extends
Reducer<Text, IntWritable, Text, IntWritable> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values) {
sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static class SequenceMapper extends
Mapper<Object, Text, Text, Text> {
private Text word = new Text();
public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {
String []sep=value.toString().split("\t");
word.set(sep[1]+"\t"+sep[0]);
System.out.println(value.toString());
context.write(word,new Text(""));
}
}
public static class SequenceReducer extends
Reducer<Text,Text,Text,Text> {
public void reduce(Text key, Iterable<Text> values,
Context context) throws IOException, InterruptedException {
String[] sep = key.toString().split("\t");
System.out.println( sep[0]+"++++++++="+ sep[1]);
context.write(key,new Text(""));
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args)
.getRemainingArgs();
if (otherArgs.length < 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "word count");
job.setJarByClass(Driver.class);
job.setMapperClass(TokenizerMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
job.waitForCompletion(true);
Configuration conf2 = new Configuration();
Job job2 = new Job(conf2, "word count1");
job2.setJarByClass(Driver.class);
job2.setMapperClass(SequenceMapper.class);
job2.setReducerClass(SequenceReducer.class);
job2.setOutputKeyClass(Text.class);
job2.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job2, new Path(otherArgs[1]));
FileOutputFormat.setOutputPath(job2, new Path(otherArgs[2]));
job2.waitForCompletion(true);
}
}
mapreduce 顺序组合的更多相关文章
- 2018.11.20-day22 类中代码的执行顺序&组合
1.类中代码的执行顺序 2.组合
- mapreduce 依赖组合
mport java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configurat ...
- 【学习笔记】--- 老男孩学Python,day16-17 初识面向对象,类名称空间,查询顺序,组合
面向过程 VS 面向对象 面向过程的程序设计的核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西. 优点是:极大的降低了写程序的复 ...
- [大牛翻译系列]Hadoop(5)MapReduce 排序:次排序(Secondary sort)
4.2 排序(SORT) 在MapReduce中,排序的目的有两个: MapReduce可以通过排序将Map输出的键分组.然后每组键调用一次reduce. 在某些需要排序的特定场景中,用户可以将作业( ...
- 【原创】MapReduce编程系列之二元排序
普通排序实现 普通排序的实现利用了按姓名的排序,调用了默认的对key的HashPartition函数来实现数据的分组.partition操作之后写入磁盘时会对数据进行排序操作(对一个分区内的数据作排序 ...
- MapReduce怎么优雅地实现全局排序
思考 想到全局排序,是否第一想到的是,从map端收集数据,shuffle到reduce来,设置一个reduce,再对reduce中的数据排序,显然这样和单机器并没有什么区别,要知道mapreduce框 ...
- 大数据技术 —— MapReduce 简介
本文为senlie原创,转载请保留此地址:http://www.cnblogs.com/senlie/ 1.概要很多计算在概念上很直观,但由于输入数据很大,为了能在合理的时间内完成,这些计算必须分布在 ...
- 数字货币量化教程——使用itertools实现各种排列组合
在量化数据处理中,经常使用itertools来完成数据的各种排列组合以寻找最优参数 一.数据准备 import itertools items = [1, 2, 3] ab = ['a', 'b'] ...
- hadoop之计数器和管道的mrunit测试
引言 hadoop的调试真心让人灰常恼火,而且从企业实际出发,集群的资源是有限的,不可能在集群上跑一遍又一遍根据log去调试代码,那么使用MRUnit编写测试单元,显得尤为重要.MRUnit中的Map ...
随机推荐
- FZU 1893 内存管理 模拟
比赛的时候队友要做这道题…… 他没做出来自己也被误导了…… 也算是个教训 自己还是要有自己的思路…… 又是模拟题…… 网上都是用vector做的 我最近才会stl 怎么会用那么高大上的的东西…… 强力 ...
- NOIP2011-普及组复赛模拟试题-第一题-NBA总冠军
题目背景 Background 一年两度的期末考要到来了!! 题目描述 Description 又要到考试了,Ljw决定放松一下,就打开电视,看见了篮球赛,他立即想到了每年的NBA总冠军队伍.由 ...
- NOIP2012-普及组复赛-第一题-质因数分解
题目描述 Description 已知正整数n是两个不同的质数的乘积,试求出两者中较大的那个质数. 输入输出格式 Input/output 输入格式:输入只有一行,包含一个正整数n.输出格式:输出只 ...
- 【Loadrunner】初学Loadrunner——参数化设置(Xml类型)
不是所有类型的参数都是和XML类型,只有一段标准的XML语句块,而且需要选中整个完整的XML语句块才可以使用XML的参数化.单个变量是不适合XML的参数化的.在选择的时候需要选中XML语句块的起始标签 ...
- 什么是JDBC?
JDBC是Java数据库连接(Java DataBase Connectivity)技术的简称,提供连接各种常用数据库的能力! 1.方式一(配置文件实现): <!-- 1. 连接池实例 --&g ...
- 肢体语言心理学+FBI阅人术(行为心理学) 用最短的时间了解一个人
肢体语言心理学 如何从站姿判断人 每个人都有自己习惯的站立姿势.美国夏威夷大学心理学家指出,不同的站姿可以显示出一个人的性格特征. 站立时习惯把双手插入裤袋的人:城府较深,不轻易向人表露内心 ...
- js几种基本数据类型及之间转换与java的不同、js数组一些常见操作
js的三大组成部分及各自作用: 1.ECMAScript:规范了js的基本语法和功能 2.DOM:js操作页面元素的API 3.BOM:js操作浏览器部分功能的API 如果通过<script s ...
- Python 数据分析包:pandas 基础
pandas 是基于 Numpy 构建的含有更高级数据结构和工具的数据分析包 类似于 Numpy 的核心是 ndarray,pandas 也是围绕着 Series 和 DataFrame 两个核心数据 ...
- 能加载文件或程序集“XXX”或它的某一个依赖项,系统找不到指定的文件
能加载文件或程序集“XXX”或它的某一个依赖项,系统找不到指定的文件 http://blog.csdn.net/pplcheer/article/details/7796211 做项目总是遇到各种的问 ...
- TCP/IP体系结构-测试人员必须理解的
如果还想在测试这条路上继续走下去的话,那么下面这些东西就是我们必须去掌握的,至少你还不想止步于简单的黑盒测试--其实,一直想去接触Linux下的应用测试,这样能学到东西会很多,而且会非常的受用.之前听 ...