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 ...
 
随机推荐
- Bootstrap 面板
			
基本的面板:<div class="panel panel-default"> <div class="panel-body"> 这是一 ...
 - 【黑金教程笔记之006】【建模篇】【Lab 05 SOS信号之一】—笔记
			
sos_module.v是产生SOS信号的功能模块.即有次序的输出莫斯码:点.画.间隔.control_module.v是一个定时触发器,每一段时间使能sos_module.v. 模块: /***** ...
 - python 面向对象十 __init__和__new__
			
一.__init__和__new__方法 __init__ 和 __new__ 最主要的区别在于:1.__init__ 通常用于初始化一个新实例,控制这个初始化的过程,比如添加一些属性, 做一些额外的 ...
 - bzoj 1907: 树的路径覆盖【贪心+树形dp】
			
我是在在做网络流最小路径覆盖的时候找到这道题的 然后发现是个贪心+树形dp \( f[i] \)表示在\( i \)为根的子树中最少有几条链,\( v[i] \) 表示在\( i \)为根的子树中\( ...
 - bzoj 3456: 城市规划【NTT+多项式求逆】
			
参考:http://blog.miskcoo.com/2015/05/bzoj-3456 首先推出递推式(上面的blog讲的挺清楚的),大概过程是正难则反,设g为n个点的简单(无重边无自环)无向图数目 ...
 - CF915E Physical Education Lessons(珂朵莉树)
			
中文题面 据说正解是动态开点线段树而且标记也不难下传的样子 然而这种区间推平的题目还是喜欢写珂朵莉树啊……码量小…… 虽然真要构造的话随便卡…… //minamoto #include<cstd ...
 - 原生js一行代码实现简易轮播图
			
这是一个简易的js无限循环轮播图,只用了一行js代码就实现了无限循环,记录一下三目运算符的伟大! <!DOCTYPE html><html lang="en"&g ...
 - java-使用反射实现ORM映射
			
自定义两个注解 package com.moon.ROM; import java.lang.annotation.ElementType; import java.lang.annotation.R ...
 - 利用OneDNS同步chrome数据
			
将DNS服务器改成OneDNS的 117.50.11.11 备用改为 117.50.22.22 然后刷新自己的DNS缓存,接着测试一下https://test.onedns.net即可 这样既可以正常 ...
 - 菜鸡CodeFoces打卡单
			
2017.12.13 1:05 签到3题 Educational Codeforces Round 34 (Rated for Div. 2) 补题: