map/reduce类简单介绍
在Hadoop的mapper类中,有4个主要的函数,分别是:setup,clearup,map,run。代码如下:
- protected void setup(Context context) throws IOException, InterruptedException {
- // NOTHING
- }
- protected void map(KEYIN key, VALUEIN value,
- Context context) throws IOException, InterruptedException {
- context.write((KEYOUT) key, (VALUEOUT) value);
- }
- protected void cleanup(Context context) throws IOException, InterruptedException {
- // NOTHING
- }
- public void run(Context context) throws IOException, InterruptedException {
- setup(context);
- while (context.nextKeyValue()) {
- map(context.getCurrentKey(), context.getCurrentValue(), context);
- }
- cleanup(context);
- }
- }
由上面的代码,我们可以了解到,当调用到map时,通常会先执行一个setup函数,最后会执行一个cleanup函数。而默认情况下,这两个函数的内容都是nothing。因此,当map方法不符合应用要求时,可以试着通过增加setup和cleanup的内容来满足应用的需求。
- /**
- * Called once at the start of the task.
- */
- protected void setup(Context context
- ) throws IOException, InterruptedException {
- // NOTHING
- }
- /**
- * This method is called once for each key. Most applications will define
- * their reduce class by overriding this method. The default implementation
- * is an identity function.
- */
- @SuppressWarnings("unchecked")
- protected void reduce(KEYIN key, Iterable<VALUEIN> values, Context context
- ) throws IOException, InterruptedException {
- for(VALUEIN value: values) {
- context.write((KEYOUT) key, (VALUEOUT) value);
- }
- }
- /**
- * Called once at the end of the task.
- */
- protected void cleanup(Context context
- ) throws IOException, InterruptedException {
- // NOTHING
- }
- /*
- * control how the reduce task works.
- */
- @SuppressWarnings("unchecked")
- public void run(Context context) throws IOException, InterruptedException {
- setup(context);
- while (context.nextKey()) {
- reduce(context.getCurrentKey(), context.getValues(), context);
- // If a back up store is used, reset it
- ((ReduceContext.ValueIterator)
- (context.getValues().iterator())).resetBackupStore();
- }
- cleanup(context);
- }
- }
map/reduce类简单介绍的更多相关文章
- oc-12-NSString 类简单介绍及用法
// 11-[掌握]NSString 类简单介绍及用法 #import <Foundation/Foundation.h> int main(int argc, const char * ...
- Tstrings类简单介绍及实例
用TStrings保存文件;var S: TStrings;begin S := TStringList.Create(); { ... } S.SaveToFile('config.txt' ...
- C++map类型 之 简单介绍
一:map的前世今生 (1)从关联容器与顺序容器说起.关联容器通过键(key)存储和读取元素.而顺序容器则通过元素在容器中的位置顺序存储和訪问元素(vector,queue,stack,list等). ...
- 12.常用类简单介绍.md
目录 1.Scanner类 2.System类 4.Object类和工具类 5.StringBuffer类和StringBuilder类 6.Math类 7.Random类和ThreadLocalRa ...
- Java学习笔记43(打印流、IO流工具类简单介绍)
打印流: 有两个类:PrintStream,PrintWriter类,两个类的方法一致,区别在于构造器 PrintStream:构造方法:接收File类型,接收字符串文件名,接收字节输出流(Outpu ...
- Java并发之Semaphore和Exchanger工具类简单介绍
一.Semaphore介绍 Semaphore意思为信号量,是用来控制同时访问特定资源的线程数数量.它的本质上其实也是一个共享锁.Semaphore可以用于做流量控制,特别是公用资源有限的应用场景.例 ...
- Java中的Number和Math类简单介绍
Java Number类 一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等. 实例: int a = 5000; float b = 13.65 ...
- java IO类简单介绍
一.流的概念 流是字节序列的抽象概念.流和文件的差别:文件是数据的静态存储形式,而流是指数据传输时的形态.文件只是流的操作对象之一.流按其操作的对象不同可以分为文件流.网络流.内存流.磁带流等.Jav ...
- android application类简单介绍(一)
每次应用程序执行时.应用程序的application类保持实例化的状态. 通过扩展applicaiton类,能够完毕下面3项工作: 1.对android执行时广播的应用程序级事件如低低内做出响应. 2 ...
随机推荐
- Gradle 引入本地定制 jar 包,而不使用坐标下载 jar 包的方法
第 1 步:创建文件夹,拷贝 jar 包 在自己的 Gradle 项目里建立一个名为 “libs” (这个名字可以自己定义,不一定非要叫这个名字)的文件夹,把自己本地的 jar 包拷贝到这个文件夹中. ...
- jquery中ajax回调函数使用this
今天在写ajax请求的的时候success中代码老是不能正常执行,找了半天的原因,代码如下: 1 $.ajax({type: 'GET', 2 url: url, 3 data: oData, 4 s ...
- HUE中oozie执行shell
Oozie执行Shell,传入参数1. 新建一个workflow 2. 拖入一个shell 3. shell脚本如下 #!/bin/sh sqoop import --connect jdbc:mys ...
- 一个问题:C#引用类型传参,说出你的答案
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { People p = new Peo ...
- Jar 包 及运行Jar包 - 转载
Eclipse的jar file和Runnable JAR file的区别 - 及bat运行Runnable JAR文件 1.两种jar的区别 jar file是最普通的jar包,即平时我们工程中li ...
- python 低版本一段扫描代码
个人在做Linux渗透测试往内网跨的时候,通常我碰到的Linux环境都会是如下集中情况 1: DMZ,严格的DMZ,根本跨不到内网里去.这种最恶心了. 2:WEB SERVER,严格区分,工作机和工作 ...
- 通过HBase API进行开发
http://www.cnblogs.com/netbloomy/p/6683509.html 一.将HBase的jar包及hbase-site.xml添加到IDE 1.到安装HBase集群的任意一台 ...
- centos7没有安装ifconfig命令的解决方法(转)
ifconfig命令是设置或显示网络接口的程序,可以显示出我们机器的网卡信息,可是有些时候最小化安装CentOS等Linux发行版的时候会默认不安装ifconfig等命令,这时候你进入终端,运行ifc ...
- android传感器使用
android传感器的使用以加速度传感器.方向传感器.磁场.压力.温度.光感.特别的距离传感器为例介绍. 首先所在的类需要implement SensorEventListener.使用传感器分为以下 ...
- django中Model表的反向查询
很多时候需要在多张表之间进行跨表查询,这其中外键是必须存在的,而通过外键所处的表的对象进行跨表查询, 称为正向查询.反之,则是反向查询. 正向查询很简单,这里不谈. 主要谈下反向查询. class U ...