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. oracle 导入数据报600错误

    之前导入一个大容量dmp数据文件,报一个600错误,咨询网上的解决方法,按上面的处理一圈也没有整好,最后咨询组里一个大神,出现此错误 思路是,单个数据文件大小最大为32G,分析数据库后解决如下: 错误 ...

  2. SQL SERVER 对权限的授予GRANT、拒绝DENY、收回REVOKE

    -----对用户member授权,允许其具有对数据表person的更新和删除的操作权限:GRANT UPDATE,DELETE ON personTO member WITH GRANT OPTION ...

  3. [开源]JSON文本格式化工具(简码万能助手开源扩展程序)

    现在的网站大多都是使用json进行API式前后端数据交互, 有时抓包得到的是一串没格式化的JSON文本, 不太方便分析, 所以我自行写了个开源扩展程序, 可以方便地格式化JSON文本.   当然,你也 ...

  4. about route

    route add default dev  my_iface1 route del default route add default gw 192.168.120.1 route add -net ...

  5. 洛谷P3812 【模板】线性基

    题目背景 这是一道模板题. 题目描述 给定n个整数(数字可能重复),求在这些数中选取任意个,使得他们的异或和最大. 输入输出格式 输入格式: 第一行一个数n,表示元素个数 接下来一行n个数 输出格式: ...

  6. centOS上的基础文件操作

    文件及文件夹的基础操作: 1: 新建     (1)在当前目录新建一个文件夹   dir foldername     (2)  新建文件:     当前目录  vi newFile.text     ...

  7. 常用EL函数汇总 fn:contains ,fn:substring,fn:substringAfter...

    由于在JSP页面中显示数据时,经常需要对显示的字符串进行处理,SUN公司针对于一些常见处理定义了一套EL函数库供开发者使用.这些EL函数在JSTL开发包中进行描述,因此在JSP页面中使用SUN公司的E ...

  8. 在 Ubuntu Linux 14.04 LTS 上安装php7

    首先添加php官方源 $ sudo add-apt-repository ppa:ondrej/php 然后更新源 $ sudo apt-get update 然后安装 $ sudo apt-get ...

  9. CSS翻转小效果

    CSS3翻转显示另外一张图: 1.backface-visibility:hidden;背面不可见 2.transform:rotate();旋转 (可以把图片换成本地图片看一下效果) <!DO ...

  10. 部署laravel项目

    1 先登录到服务器上,将代码克隆下来 git clone 项目地址 2 避免composer太慢,启用本镜像服务 可以先安装 apt-get install zip,unzip,php7.0-zip ...