当前位置: 首页 > news >正文

MapReduce实例——查询缺失扑克牌

问题:

 解决:

首先分为两个过程,Map过程将<=10的牌去掉,然后只针对于>10的牌进行分类,Reduce过程,将Map传过来的键值对进行统计,然后计算出少于3张牌的的花色

 

1.代码

1) Map代码

1     String line = value.toString();
2     String[] strs = line.split("-");
3     if(strs.length == 2){
4         int number = Integer.valueOf(strs[1]);
5         if(number > 10){
6             context.write(new Text(strs[0]), value);
7         }
8     }

 

 

2) Reduce代码

1      Iterator<Text> iter = values.iterator();
2      int count = 0;
3      while(iter.hasNext()){
4         iter.next();
5         count ++;
6     }
7     if(count < 3){
8         context.write(key, NullWritable.get());
9     }

 

 

3) Runner代码

 1     Configuration conf = new Configuration();
 2     Job job = Job.getInstance(conf);
 3     job.setJobName("poker mr");
 4     job.setJarByClass(pokerRunner.class);
 5             
 6     job.setMapperClass(pakerMapper.class);
 7     job.setReducerClass(pakerRedue.class);
 8             
 9     job.setMapOutputKeyClass(Text.class);
10     job.setMapOutputValueClass(Text.class);
11             
12     job.setOutputKeyClass(Text.class);
13     job.setOutputValueClass(NullWriter.class);
14             
15     FileInputFormat.addInputPath(job, new Path(args[0]));
16     FileOutputFormat.setOutputPath(job, new Path(args[1]));
17             
18     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 /

 

转载于:https://www.cnblogs.com/langgj/p/6612566.html

相关文章:

  • list内变量排序
  • 【bzoj1507】 JSOI2008—Blue Mary的旅行
  • JZOJ 3.25 1420——【汕头市选2012初中组】求和(sum)
  • 报表reportviewer控件使用时,单行文本过长的解决办法
  • 【VB超简单入门】五、基本输出输入
  • WordPress基础知识:条件判断标签及用法大全
  • EF Code-First 学习之旅 Code First Conventions
  • Excel从零整理
  • 线段树建图
  • C#编程(七十六)----------使用指针实现基于栈的高性能数组
  • CSS-样式表的分类以及选择器的分类
  • childNodes与children
  • 发现一个很N且免费的html5拓扑图 关系图 生成组件
  • I2S
  • Oracle11g表空间导入dmp数据
  • CODING 缺陷管理功能正式开始公测
  • echarts的各种常用效果展示
  • ECS应用管理最佳实践
  • Java IO学习笔记一
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • oschina
  • SpiderData 2019年2月23日 DApp数据排行榜
  • Spring-boot 启动时碰到的错误
  • Swift 中的尾递归和蹦床
  • Terraform入门 - 1. 安装Terraform
  • vue数据传递--我有特殊的实现技巧
  • -- 查询加强-- 使用如何where子句进行筛选,% _ like的使用
  • 分享一份非常强势的Android面试题
  • 欢迎参加第二届中国游戏开发者大会
  • 记一次和乔布斯合作最难忘的经历
  • 今年的LC3大会没了?
  • 聊聊flink的BlobWriter
  • 区块链技术特点之去中心化特性
  • 微信小程序:实现悬浮返回和分享按钮
  • 我与Jetbrains的这些年
  • 不要一棍子打翻所有黑盒模型,其实可以让它们发挥作用 ...
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • ​ 轻量应用服务器:亚马逊云科技打造全球领先的云计算解决方案
  • ​虚拟化系列介绍(十)
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (十三)Java springcloud B2B2C o2o多用户商城 springcloud架构 - SSO单点登录之OAuth2.0 根据token获取用户信息(4)...
  • (一)基于IDEA的JAVA基础12
  • (转)创业的注意事项
  • (转)项目管理杂谈-我所期望的新人
  • (转载)虚函数剖析
  • .net core 6 使用注解自动注入实例,无需构造注入 autowrite4net
  • .net流程开发平台的一些难点(1)
  • @Autowired和@Resource的区别
  • @Bean, @Component, @Configuration简析
  • [ 云计算 | AWS 实践 ] Java 如何重命名 Amazon S3 中的文件和文件夹
  • [<MySQL优化总结>]
  • [AMQP Connection 127.0.0.1:5672] An unexpected connection driver error occured
  • [C# 基础知识系列]专题十六:Linq介绍