MapReduce实例——查询缺失扑克牌
问题:
解决:
首先分为两个过程,Map过程将<=10的牌去掉,然后只针对于>10的牌进行分类,Reduce过程,将Map传过来的键值对进行统计,然后计算出少于3张牌的的花色
1.代码
1) Map代码
String line = value.toString();
String[] strs = line.split("-");
if(strs.length == 2){
int number = Integer.valueOf(strs[1]);
if(number > 10){
context.write(new Text(strs[0]), value);
}
}
2) Reduce代码
Iterator<Text> iter = values.iterator();
int count = 0;
while(iter.hasNext()){
iter.next();
count ++;
}
if(count < 3){
context.write(key, NullWritable.get());
}
3) Runner代码
Configuration conf = new Configuration();
Job job = Job.getInstance(conf);
job.setJobName("poker mr");
job.setJarByClass(pokerRunner.class); job.setMapperClass(pakerMapper.class);
job.setReducerClass(pakerRedue.class); job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class); job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWriter.class); FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1])); job.waitForCompletion(true);
2.运行结果
File System Counters
FILE: Number of bytes read=87
FILE: Number of bytes written=211167
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=366
HDFS: Number of bytes written=6
HDFS: Number of read operations=6
HDFS: Number of large read operations=0
HDFS: Number of write operations=2
Job Counters
Launched map tasks=1
Launched reduce tasks=1
Data-local map tasks=1
Total time spent by all maps in occupied slots (ms)=109577
Total time spent by all reduces in occupied slots (ms)=42668
Total time spent by all map tasks (ms)=109577
Total time spent by all reduce tasks (ms)=42668
Total vcore-seconds taken by all map tasks=109577
Total vcore-seconds taken by all reduce tasks=42668
Total megabyte-seconds taken by all map tasks=112206848
Total megabyte-seconds taken by all reduce tasks=43692032
Map-Reduce Framework
Map input records=49
Map output records=9
Map output bytes=63
Map output materialized bytes=87
Input split bytes=110
Combine input records=0
Combine output records=0
Reduce input groups=4
Reduce shuffle bytes=87
Reduce input records=9
Reduce output records=3
Spilled Records=18
Shuffled Maps =1
Failed Shuffles=0
Merged Map outputs=1
GC time elapsed (ms)=992
CPU time spent (ms)=3150
Physical memory (bytes) snapshot=210063360
Virtual memory (bytes) snapshot=652480512
Total committed heap usage (bytes)=129871872
Shuffle Errors
BAD_ID=0
CONNECTION=0
IO_ERROR=0
WRONG_LENGTH=0
WRONG_MAP=0
WRONG_REDUCE=0
File Input Format Counters
Bytes Read=256
File Output Format Counters
Bytes Written=6
3.运行方法
在Eclipse里编译好,生出jar包,然后上传到linux系统上,在集群上运行该文件
运行命令:bin/hadoop **.jar 类包名 /
例如:bin/hadoop **.jar com.test.mr /
MapReduce实例——查询缺失扑克牌的更多相关文章
- MapReduce实例2(自定义compare、partition)& shuffle机制
MapReduce实例2(自定义compare.partition)& shuffle机制 实例:统计流量 有一份流量数据,结构是:时间戳.手机号.....上行流量.下行流量,需求是统计每个用 ...
- Spring Data JPA 实例查询
一.相关接口方法 在继承JpaRepository接口后,自动拥有了按"实例"进行查询的诸多方法.这些方法主要在两个接口中定义,一是QueryByExampleExecut ...
- MapReduce实例&YARN框架
MapReduce实例&YARN框架 一个wordcount程序 统计一个相当大的数据文件中,每个单词出现的个数. 一.分析map和reduce的工作 map: 切分单词 遍历单词数据输出 r ...
- Hibernate- 动态实例查询
什么是动态实例查询: 就是将查询出的单一列的字段,重新封装成对象,如果不适用特殊方法,会返回Object对象数组. 01.搭建环境 02.动态实例查询 需要使用相应的构造方法: public Book ...
- 如何玩转跨库Join?跨数据库实例查询应用实践
背景 随着业务复杂程度的提高.数据规模的增长,越来越多的公司选择对其在线业务数据库进行垂直或水平拆分,甚至选择不同的数据库类型以满足其业务需求.原本在同一数据库实例里就能实现的SQL查询,现在需要跨多 ...
- 实战课堂 | DMS企业版教你用一条SQL搞定跨实例查询
背景 数据管理DMS企业版提供了安全.高效地管理大规模数据库的服务.面对多元的数据库实例,为了更方便地查询被“散落”在各个地方的业务数据,我们在DMS企业版中提供了跨数据库实例查询服务. 什么是跨实例 ...
- 基于MongoDB分布式存储进行MapReduce并行查询
中介绍了如何基于Mongodb进行关系型数据的分布式存储,有了存储就会牵扯到查询.虽然用普通的方式也可以进行查询,但今天要介绍的是如何使用MONGODB中提供的MapReduce功能进行查询. ...
- MapReduce实例浅析
在文章<MapReduce原理与设计思想>中,详细剖析了MapReduce的原理,这篇文章则通过实例重点剖析MapReduce 本文地址:http://www.cnblogs.com/ar ...
- MapReduce实例
1.WordCount(统计单词) 经典的运用MapReuce编程模型的实例 1.1 Description 给定一系列的单词/数据,输出每个单词/数据的数量 1.2 Sample a is b is ...
随机推荐
- TCP、UDP和HTTP关系
TCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层.IP:网络层协议: TCP和UDP:传输层协议:TCP提供有保证的数据传输,UDP不提供. HTTP:应用层协议(超文本传输协议): 如 ...
- Node 基本使用
node -v:查看node版本 npm -v:查看npm版本 npm install npm -g :升级npm版本 npm install <module_name> [-g]:安装指 ...
- SQL Server 语法注意
1.order by select a1,a1 from temp order by a1 此语句在高版本中执行提示a1列名不明确,在低版本中执行成功!
- hasLayout原理【转】
项目中经常用到:*html .clearfix{ height:1%;} //IE6能识别*+html .clearfix{height:1%;} //IE7能识别1,有很多方式能触发hasLayo ...
- 1.1.1最短路(Floyd、Dijstra、BellmanFord)
转载自hr_whisper大佬的博客 [ 一.Dijkstra 比较详细的迪杰斯特拉算法讲解传送门 Dijkstra单源最短路算法,即计算从起点出发到每个点的最短路.所以Dijkstra常常作为其他算 ...
- ORACLE数据库的备份分为物理备份和逻辑备份两种。
物理备份是将实际组成数据库的操作系统文件从一处拷贝到另一处的备份过程,通常是从磁盘到磁带.可以使用 Oracle 的恢复管理器(Recovery Manager,RMAN)或操作系统命令进行数据库的物 ...
- windows系统下在忘记安装make的Cygwin中如何正确安装make(图文详解)
由于我在安装cygwin时忘了包含make包,所以安装后发现我在bash中无法使用make命令.但是一般在cygwin下面的软件都是要用make来实现编译和安装的.没有make,又如何编译生成make ...
- Android开发学习——游戏开发小demo
public class MainActivity extends Activity { private GameUI gameUI; @Override protected void onCreat ...
- windwsform登录页面
简单登录设计: 读取用户名密码 数据库表 实体类 数据访问类: 隐藏登录页面: 回车快捷键: 传值到main窗口:
- 11.2Java-多态
一.父类 public class Fu { public void show(){ System.out.println("父类"); } } 二.子类 public class ...