问题:

解决:

首先分为两个过程,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实例——查询缺失扑克牌的更多相关文章

  1. MapReduce实例2(自定义compare、partition)& shuffle机制

    MapReduce实例2(自定义compare.partition)& shuffle机制 实例:统计流量 有一份流量数据,结构是:时间戳.手机号.....上行流量.下行流量,需求是统计每个用 ...

  2. Spring Data JPA 实例查询

    一.相关接口方法     在继承JpaRepository接口后,自动拥有了按"实例"进行查询的诸多方法.这些方法主要在两个接口中定义,一是QueryByExampleExecut ...

  3. MapReduce实例&YARN框架

    MapReduce实例&YARN框架 一个wordcount程序 统计一个相当大的数据文件中,每个单词出现的个数. 一.分析map和reduce的工作 map: 切分单词 遍历单词数据输出 r ...

  4. Hibernate- 动态实例查询

    什么是动态实例查询: 就是将查询出的单一列的字段,重新封装成对象,如果不适用特殊方法,会返回Object对象数组. 01.搭建环境 02.动态实例查询 需要使用相应的构造方法: public Book ...

  5. 如何玩转跨库Join?跨数据库实例查询应用实践

    背景 随着业务复杂程度的提高.数据规模的增长,越来越多的公司选择对其在线业务数据库进行垂直或水平拆分,甚至选择不同的数据库类型以满足其业务需求.原本在同一数据库实例里就能实现的SQL查询,现在需要跨多 ...

  6. 实战课堂 | DMS企业版教你用一条SQL搞定跨实例查询

    背景 数据管理DMS企业版提供了安全.高效地管理大规模数据库的服务.面对多元的数据库实例,为了更方便地查询被“散落”在各个地方的业务数据,我们在DMS企业版中提供了跨数据库实例查询服务. 什么是跨实例 ...

  7. 基于MongoDB分布式存储进行MapReduce并行查询

    中介绍了如何基于Mongodb进行关系型数据的分布式存储,有了存储就会牵扯到查询.虽然用普通的方式也可以进行查询,但今天要介绍的是如何使用MONGODB中提供的MapReduce功能进行查询.     ...

  8. MapReduce实例浅析

    在文章<MapReduce原理与设计思想>中,详细剖析了MapReduce的原理,这篇文章则通过实例重点剖析MapReduce 本文地址:http://www.cnblogs.com/ar ...

  9. MapReduce实例

    1.WordCount(统计单词) 经典的运用MapReuce编程模型的实例 1.1 Description 给定一系列的单词/数据,输出每个单词/数据的数量 1.2 Sample a is b is ...

随机推荐

  1. MVC视图中下拉框的使用

    一.一般变量或对象的绑定 首先要在controller 中将选项设置成 selecList对象,并赋值给viewBag动态对象. public ActionResult Index(string mo ...

  2. java笔记线程的生命周期图解

  3. Objective-C NSData/NSMutableData

    创建于完成: 2018/02/06 总览: http://www.cnblogs.com/lancgg/p/8404975.html  数据类   简介 处理比特列 Foundation/NSData ...

  4. mybatis基础学习5-一对多和多对多(简写)

    1:建实体类 建mysql表

  5. bzoj 3609: [Heoi2014]人人尽说江南好【博弈论】

    参考:https://blog.csdn.net/Izumi_Hanako/article/details/80189596 胜负和操作次数有关,先手胜为奇,所以先手期望奇数后手期望偶数,最后一定能达 ...

  6. 设置mysql 定时备份任务

    1 修改配置文件  /etc/my.conf (为了命令 mysqldump能省略输入密码执行,mysql5.5 之后已经不建议控制台直接输入密码的方式) 增加如下配置 [client]host=lo ...

  7. MVC、MVP和MVVM的更简单易懂的理解

    本篇转自网络: 一.MVC MVC模式的意思是,软件可以分成三个部分. 视图(View):用户界面. 控制器(Controller):业务逻辑 模型(Model):数据保存 各部分之间的通信方式如下. ...

  8. NDK(10)Android.mk各属性简介,Android.mk 常用模板--未完

    参考 : http://blog.csdn.net/hudashi/article/details/7059006 1. Android.mk简介 Android.mk文件是GNU Makefile的 ...

  9. 为HttpClient和HttpURLConnection添加中国移动代理

    转自: http://www.2cto.com/kf/201111/112100.html 在android中,一般需要联网的时候前,都要做一次网络的判断,判断当前的网络状态!然后开始请求网络 当我们 ...

  10. ava的动态代理机制详解

    在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...