Top 10 IDs base on their value

First , we need to set the reduce to 1. For each map task, it is not a good idea to output each key/value pair. Instead, we can just output the top 10 IDs based on their value. So, less data will be written to disk and transferred to the reducer. If we need to get the top 10 for each mapper task, we need to iterator over the whole split. In map function, we collect each id/value, add it to the data structure that supports sorting like black-red tree, keep only the top 10. In the cleanup function, we output the result.

 //hadoop code for map/reduce task , see the cleanup function.
public void run(Context context) throws IOException, InterruptedException {
setup(context);
try {
while (context.nextKey()) {
reduce(context.getCurrentKey(), context.getValues(), context);
}
} finally {
cleanup(context);
}
}

The map task below. the sorted IDs is written in cleanup function.

The reduce task has the similar logic.(Note: there is only 1 reducer)

reference:https://www.youtube.com/watch?v=Bj6-maOjB8M

Map Reduce Application(Top 10 IDs base on their value)的更多相关文章

  1. Map Reduce Application(Partitioninig/Binning)

    Map Reduce Application(Partitioninig/Group data by a defined key) Assuming we want to group data by ...

  2. Map Reduce Application(Join)

    We are going to explain how join works in MR , we will focus on reduce side join and map side join. ...

  3. mapreduce: 揭秘InputFormat--掌控Map Reduce任务执行的利器

    随着越来越多的公司采用Hadoop,它所处理的问题类型也变得愈发多元化.随着Hadoop适用场景数量的不断膨胀,控制好怎样执行以及何处执行map任务显得至关重要.实现这种控制的方法之一就是自定义Inp ...

  4. OWAP Top 10

    2013 Top 10 List   A1-Injection Injection flaws, such as SQL, OS, and LDAP injection occur when untr ...

  5. Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)...啊啊啊

    函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单的任务,这种分解可以称之为面向过程的程序设计.函数就是面向过程的程序设计 ...

  6. 安全检测:2013 Top 10 List

    转自:https://www.owasp.org/index.php/Top_10_2013-Top_10   Risk 2013 Table of Contents 2013 Top 10 List ...

  7. (转)Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)

    原文:https://www.cnblogs.com/chenwolong/p/reduce.html 函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数 ...

  8. Chapter 3 Top 10 List

    3.1 Introduction Given a set of (key-as-string, value-as-integer) pairs, then finding a Top-N ( wher ...

  9. MapReduce剖析笔记之三:Job的Map/Reduce Task初始化

    上一节分析了Job由JobClient提交到JobTracker的流程,利用RPC机制,JobTracker接收到Job ID和Job所在HDFS的目录,够早了JobInProgress对象,丢入队列 ...

随机推荐

  1. 商业化IM 客户端设计---Message模型

    在IM开发中,一个问题是怎么管理传输,包括处理消息发送,消息接受和怎么转发等等,就是上一篇文章提到的IMService扮演的角色.另一个问题就是传输的具体数据是怎么定义的,既包括业务数据(文字,语音, ...

  2. NDK-C++ support

    1.NDK相关各种可用的C++运行库Android平台自带微型C++运行库(system),NDK提供补充功能的C++运行库(gabi++, stlport, gnustl)运行库 异常支持 RTTI ...

  3. 更新UI放在主线程的原因

    1.在子线程中是不能进行UI 更新的,而可以立刻更新的原因是:子线程代码执行完毕了,又自动进入到了主线程,这中间的时间非常的短,让我们误以为子线程可以更新UI.如果子线程一直在运行,则无法更新UI,因 ...

  4. GPUImage源码解读之GPUImageFramebuffer

    简介 OpenGL ES的FrameBuffer是渲染发生的地方,普通的2D图形的渲染默认发生在屏幕上:而三维的图形渲染则除了包括像素点的颜色,还有Depth Buffer,Stencil Buffe ...

  5. vector,set常见方法

    vector push_back() 压入元素 size()返回元素个数 swap()交换两个向量的位置 erase()任意位置删除元素 reverse(a.begin(),a.end())翻转 se ...

  6. window安装ubuntu系统

  7. thinkphp5 部署到iis服务器url重写

    thinkphp部署到iis服务器配置url重写的解决方法: 1.下载 url rewrite.下载地址:https://www.iis.net/downloads/microsoft/url-rew ...

  8. 计算机基础和Linux基础

    计算机原理 计算机发展史 机器语言—让机器干活 差分机—让机器的数学运算和逻辑运算只简化成“加法”,计算机只处理“加法” 计算机硬件CPU=运算器+控制器+寄存器(缓存)硬盘=存储器+寄存器寄存器是为 ...

  9. gsl 复数

    一.复数的表示 复数的两种表示: gsl复数结构的声明和部分宏在gsl_complex.h中,方法的声明和另一部分宏在gsl_complex_math.h.复数的表示(结构)有三种,即float型.d ...

  10. Java设计模式(5)——创建型模式之建造者模式(Builder)

    一.概述 概念 将一个复杂的构建与其表示相分离,使得同样的构建过程可以创建不同的表示.(与工厂类不同的是它用于创建复合对象) UML图   主要角色 抽象建造者(Builder)——规范建造方法与结果 ...