问题:

解决:

首先分为两个过程,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. wincap的安装与环境配置

    首先开始知道什么是wincap? 1 通常情况下,大多数的网络应用程序都是通过操作系统来访问网络(sockets),这样是算比较简单的了,毕竟已经封装好了 ,有的时候呢需要一些底层的细节比如协议处理, ...

  2. java中static,super,final关键字辨析

    1:static关键字 利:1)对对象的共享数据提供单独的空间存储. 2)修饰的方法可以直接被类名调用 弊:1)生命周期长. 2)访问出现限制(只能访问静态) 它可以有静态方法,静态类,静态变量 2: ...

  3. idea 快捷键以及包含字符串文件搜索

    1.idea也有一个类似于eclipse的包含字符串文件搜索(特别实用) idea 里按快捷键:ctrl+H 2.下图是idea的快捷键汇总 3.debug调试 F5:跳入方法   F6:向下逐行调试 ...

  4. bzoj 3894 文理分科【最小割+dinic】

    谁说这道和2127是双倍经验的来着完全不一样啊? 数组开小会TLE!数组开小会TLE!数组开小会TLE! 首先sum统计所有收益 对于当前点\( (i,j) \)考虑,设\( x=(i-1)*m+j ...

  5. 进击的Python【第八章】:动态导入模块、断言、socket开发之SSH,FTP

    一.动态导入模块 知道一个模块名的字符串形式,通过字符串来导入模块 mod = __import__("lib.aa") print(mod) instance = getattr ...

  6. poj 2299 Ultra-QuickSort 归并排序求逆序数对

    题目链接: http://poj.org/problem?id=2299 题目描述: 给一个有n(n<=500000)个数的杂乱序列,问:如果用冒泡排序,把这n个数排成升序,需要交换几次? 解题 ...

  7. [hdu1695] GCD【莫比乌斯反演】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1695 先把题目转化为求一个数在区间[1, b / k],另一个数在区间[1, d / k]时,这两个数互 ...

  8. Oracle11g导出dmp并导入Oracle10g的操作记录

    Oracle11g导出dmp并导入Oracle10g的操作记录. 操作环境说明: Oracle11g环境:Windows7,Oracle Database 11g Enterprise Edition ...

  9. TC 609DIV2(950)

    Problem Statement      Vocaloids Gumi, Ia, and Mayu love singing. They decided to make an album comp ...

  10. Android开发学习——android与服务器端数据交互

    1.首先搭建服务器端. 使用MyEclipse开发工具 public class MyServlet extends HttpServlet { @Override protected void do ...