MapReduce

Is it better to use the mapred or the mapreduce package to create a Hadoop Job?

佐手、 提交于 2019-12-17 04:25:14
问题 To create MapReduce jobs you can either use the old org.apache.hadoop.mapred package or the newer org.apache.hadoop.mapreduce package for Mappers and Reducers, Jobs ... The first one had been marked as deprecated but this got reverted meanwhile. Now I wonder whether it is better to use the old mapred package or the new mapreduce package to create a job and why. Or is it just dependent on whether you need stuff like the MultipleTextOutputFormat which is only available in the old mapred package

Using map/reduce for mapping the properties in a collection

前提是你 提交于 2019-12-17 03:57:32
问题 Update: follow-up to MongoDB Get names of all keys in collection. As pointed out by Kristina, one can use Mongodb 's map/reduce to list the keys in a collection: db.things.insert( { type : ['dog', 'cat'] } ); db.things.insert( { egg : ['cat'] } ); db.things.insert( { type : [] }); db.things.insert( { hello : [] } ); mr = db.runCommand({"mapreduce" : "things", "map" : function() { for (var key in this) { emit(key, null); } }, "reduce" : function(key, stuff) { return null; }}) db[mr.result]

Using map/reduce for mapping the properties in a collection

若如初见. 提交于 2019-12-17 03:56:05
问题 Update: follow-up to MongoDB Get names of all keys in collection. As pointed out by Kristina, one can use Mongodb 's map/reduce to list the keys in a collection: db.things.insert( { type : ['dog', 'cat'] } ); db.things.insert( { egg : ['cat'] } ); db.things.insert( { type : [] }); db.things.insert( { hello : [] } ); mr = db.runCommand({"mapreduce" : "things", "map" : function() { for (var key in this) { emit(key, null); } }, "reduce" : function(key, stuff) { return null; }}) db[mr.result]

What is the purpose of shuffling and sorting phase in the reducer in Map Reduce Programming?

佐手、 提交于 2019-12-17 02:39:45
问题 In Map Reduce programming the reduce phase has shuffling, sorting and reduce as its sub-parts. Sorting is a costly affair. What is the purpose of shuffling and sorting phase in the reducer in Map Reduce Programming? 回答1: First of all shuffling is the process of transfering data from the mappers to the reducers, so I think it is obvious that it is necessary for the reducers, since otherwise, they wouldn't be able to have any input (or input from every mapper). Shuffling can start even before

Check if every element in array matches condition

£可爱£侵袭症+ 提交于 2019-12-17 02:38:19
问题 I have a collection of documents: date: Date users: [ { user: 1, group: 1 } { user: 5, group: 2 } ] date: Date users: [ { user: 1, group: 1 } { user: 3, group: 2 } ] I would like to query against this collection to find all documents where every user id in my array of users is in another array, [1, 5, 7]. In this example, only the first document matches. The best solution I've been able to find is to do: $where: function() { var ids = [1, 5, 7]; return this.users.every(function(u) { return

merge output files after reduce phase

天大地大妈咪最大 提交于 2019-12-17 01:42:50
问题 In mapreduce each reduce task write its output to a file named part-r-nnnnn where nnnnn is a partition ID associated with the reduce task. Does map/reduce merge these files? If yes, how? 回答1: Instead of doing the file merging on your own, you can delegate the entire merging of the reduce output files by calling: hadoop fs -getmerge /output/dir/on/hdfs/ /desired/local/output/file.txt Note This combines the HDFS files locally. Make sure you have enough disk space before running 回答2: No, these

用形象的比喻描述大数据的生态

时光毁灭记忆、已成空白 提交于 2019-12-17 01:14:11
本文转自于知乎 Xiaoyu Ma 链接:https://www.zhihu.com/question/27974418/answer/38965760 大数据本身是个很宽泛的概念,Hadoop生态圈(或者泛生态圈)基本上都是为了处理超过单机尺度的数据处理而诞生的。你可以把它比作一个厨房所以需要的各种工具。锅碗瓢盆,各有各的用处,互相之间又有重合。你可以用汤锅直接当碗吃饭喝汤,你可以用小刀或者刨子去皮。但是每个工具有自己的特性,虽然奇怪的组合也能工作,但是未必是最佳选择。 大数据,首先你要能存的下大数据。 传统的文件系统是单机的,不能横跨不同的机器。HDFS(Hadoop Distributed FileSystem)的设计本质上是为了大量的数据能横跨成百上千台机器,但是你看到的是一个文件系统而不是很多文件系统。比如你说我要获取/hdfs/tmp/file1的数据,你引用的是一个文件路径,但是实际的数据存放在很多不同的机器上。你作为用户,不需要知道这些,就好比在单机上你不关心文件分散在什么磁道什么扇区一样。HDFS为你管理这些数据。 存的下数据之后,你就开始考虑怎么处理数据。虽然HDFS可以为你整体管理不同机器上的数据,但是这些数据太大了。一台机器读取成T上P的数据(很大的数据哦,比如整个东京热有史以来所有高清电影的大小甚至更大),一台机器慢慢跑也许需要好几天甚至好几周

2017.5.10 MapReduce内部逻辑

元气小坏坏 提交于 2019-12-16 18:14:16
MapReduce内部逻辑 Split:HDFS 中的数据以 Split 方式作为 MapReduce 的输入 Block 是 HDFS 术语,Split 是 MapReduce 术语 通常1个 Split 对应1个 block,也可能对应多个block,具体是由 InputFormat 和压缩格式决定的 默认情况下,使用的是TextInputFormat,这时1个Split对应1个block,上图4个Split对应4个Block Mapper解析出的数据输出到本地磁盘上 Map阶段由一批同时运行的Map Task 组成,每个 Map Task由3个部分组成: InputFormat:对输入数据格式进行解析,默认为TextInputFormat,key代表每行偏移量,value代表每行数据内容。 Mapper:输入数据处理 Partitioner:数据分组, Mapper 的输出key会经过 Partitioner 分组选择不同的Reduce。默认Partitioner 会对 map 输出的key进行hash取模,比如有6个Reduce Task,它就是模(mod)6,如果key的hash值为0,就选择第0个 Reduce Task。这样不同的map 对相同key,它的 hash 值取模是一样的 Reduce 阶段由一批同时运行的 Reduce Task 组成,每个 Reduce

运行Hadoop自带的MapReduce程序WordCount

北城余情 提交于 2019-12-15 09:06:24
Hadoop自带了个单词计数的MapReduce程序WordCount,下面用三种方法运行该程序 在开始前先在hdfs上面创建输入和输出路径: 1、使用 hdfs dfs -mkdir /input 命令创建一个input文件夹 2、使用 hdfs dfs -put /home/kingssm/input/data.dat /input 命令将需要执行的文件上传到hdfs上的输入文件夹 3、使用 hdfs dfs -mkdir /output 命令创建输出文件夹,因为hadoop要求输出文件夹不能存在,所以这只是空文件夹,在执行时再确定输出文件夹,如、output/output1 一、Linux系统上直接运行jar包 进入文件查看,最后一个就是我们要执行的程序 运行程序 :输入命令进行执行 hadoop jar /usr/hadoop/hadoop-3.1.3/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar wordcount /input /output/output222 如果觉得太长了可以先进入到mapreduce目录再执行。 解释 :hadoop jar是hadoop执行jar文件必须写的命令,中间很长的是jar包的路径,wordcount是启动类,/input是输入路径,/output

Hadoop-MapReduce+HDFS文件格式和压缩格式+split和Maptask关系+WordCount剖析+shuffle理解

最后都变了- 提交于 2019-12-15 01:47:13
一. MapReduce on Yarn流程 1. 什么是MapReduce MapReduce是一个计算框架,核心思想是"分而治之",表现形式是有个输入(input),mapreduce操作这个输入(input),通过本身定义好的计算模型,得到一个输出(output),这个输出就是我们所需要的结果。在运行一个mapreduce计算任务时候,任务过程被分为两个阶段:map阶段和reduce阶段,每个阶段都是用键值对(key/value)作为输入(input)和输出(output)。而程序员要做的就是定义好这两个阶段的函数:map函数和reduce函数。 Map:映射过程,把一组数据按照某种Map函数映射成新的数据。每一行解析成一个 <k,v> 键值对。每一个键值对调用一次map函数,生成一个新的 <k,v> 键值对 Shuffle:洗牌,对数据映射的排序、分组、拷贝。 Reduce:归约过程,把若干组映射结果进行汇总并输出。 2. Yarn的作用 Yarn:ResourceManager,NodeManager RM:application Manager 应用程序管理器 resource scheduler 资源memory+cpu调度器 ResourceManager :负责资源管理。在运行过程中,整个系统有且只有一个RM,系统的资源由RM来负责调度管理