MapReduce库类

时间:2022-09-22 10:51:00

Hadoop除了可以让开发人员自行编写map函数和reduce函数,还提供一些常用函数(mapper、reducer和partitioner)的类库,这些类位于 org.apache.hadoop.mapred.lib 包内,在1.2.1版,该包包含一个接口和若干类。在org.apache.hadoop.mapreduce.lib 包内也存在相关类库,且有部分重复。mapred包内部是旧API,mapreduce包是重构之后的新API,但两者都可以使用。

接口如下:

InputSampler.Sampler<K,V> Interface to sample using an InputFormat.

类如下:

BinaryPartitioner<V> Partition BinaryComparable keys using a configurable part of the bytes array returned by BinaryComparable.getBytes().
ChainMapper The ChainMapper class allows to use multiple Mapper classes within a single Map task.
ChainReducer The ChainReducer class allows to chain multiple Mapper classes after a Reducer within the Reducer task.
CombineFileInputFormat<K,V> An abstract InputFormat that returns CombineFileSplit's in InputFormat.getSplits(JobConf, int) method.
CombineFileRecordReader<K,V> A generic RecordReader that can hand out different recordReaders for each chunk in a CombineFileSplit.
CombineFileSplit A sub-collection of input files.
DelegatingInputFormat<K,V> An InputFormat that delegates behaviour of paths to multiple other InputFormats.
DelegatingMapper<K1,V1,K2,V2> An Mapper that delegates behaviour of paths to multiple other mappers.
FieldSelectionMapReduce<K,V> This class implements a mapper/reducer class that can be used to perform field selections in a manner similar to unix cut.
HashPartitioner<K2,V2> Partition keys by their Object.hashCode().
IdentityMapper<K,V> Implements the identity function, mapping inputs directly to outputs.
IdentityReducer<K,V> Performs no reduction, writing all input values directly to the output.
InputSampler<K,V> Utility for collecting samples and writing a partition file for TotalOrderPartitioner.
InputSampler.IntervalSampler<K,V> Sample from s splits at regular intervals.
InputSampler.RandomSampler<K,V> Sample from random points in the input.
InputSampler.SplitSampler<K,V> Samples the first n records from s splits.
InverseMapper<K,V> Mapper that swaps keys and values.
KeyFieldBasedComparator<K,V> This comparator implementation provides a subset of the features provided by the Unix/GNU Sort.
KeyFieldBasedPartitioner<K2,V2> Defines a way to partition keys based on certain key fields (also see KeyFieldBasedComparator.
LongSumReducer<K> Reducer that sums long values.
MultipleInputs This class supports MapReduce jobs that have multiple input paths with a different InputFormat and Mapper for each path
MultipleOutputFormat<K,V> This abstract class extends the FileOutputFormat, allowing to write the output data to different output files.
MultipleOutputs The MultipleOutputs class simplifies writting to additional outputs other than the job default output via the OutputCollectorpassed to the map() and reduce() methods of the Mapper and Reducer implementations.
MultipleSequenceFileOutputFormat<K,V> This class extends the MultipleOutputFormat, allowing to write the output data to different output files in sequence file output format.
MultipleTextOutputFormat<K,V> This class extends the MultipleOutputFormat, allowing to write the output data to different output files in Text output format.
MultithreadedMapRunner<K1,V1,K2,V2> Multithreaded implementation for @link org.apache.hadoop.mapred.MapRunnable.
NLineInputFormat NLineInputFormat which splits N lines of input as one split.
NullOutputFormat<K,V> Consume all outputs and put them in /dev/null.
RegexMapper<K> Mapper that extracts text matching a regular expression.
TokenCountMapper<K> Mapper that maps text values into <token,freq>pairs.
TotalOrderPartitioner<K extends WritableComparable,V> Partitioner effecting a total order by reading split points from an externally generated source.

目前,用到的有一下几个类,后续将对其他类及接口进行研究。

1)ChainMapper类和ChainReducer类:可以在一个mapper中运行多个mapper,再运行reducer,之后还可以再运行多个mapper。这两个类组合使用,用于需要执行多个mapreduce过程的情况。这个方案可以明显降低磁盘的I/O开销。

2)TokenCounterMapper类:将输入值分解成独立的单词(使用Java的StringTokenizer)、输出各单词及其计数器(值为1)

3)InverseMapper类:一个能交换键和值的mapper

参考资料:

1. hadoop API 文档

2. Hadoop 权威指南

MapReduce库类的更多相关文章

  1. 代码的坏味道(22)——不完美的库类&lpar;Incomplete Library Class&rpar;

    坏味道--不完美的库类(Incomplete Library Class) 特征 当一个类库已经不能满足实际需要时,你就不得不改变这个库(如果这个库是只读的,那就没辙了). 问题原因 许多编程技术都建 ...

  2. &period;Net Core库类项目跨项目读取配置文件

    在项目开始之前我们可以先去了解一下IConfiguration接口,.Net Core Web应用程序类似于一个控制台,当程序运行到Startup时会自动注入IConfiguration,默认读取当前 ...

  3. python安装pip和使用pip安装Python库类比如pip安装beautifulsoup4

    初学Python时,看到很多不懂得东西,比如 pip, 是python 包管理工具,pip是easy_install的取代. Distribute是对标准库disutils模块的增强,我们知道disu ...

  4. C&plus;&plus; &vert; boost库 类的序列化

    是的,这是今年的情人节,一篇还在研究怎么用的文章,文结的时候应该就用成功了. 恩,要有信心 神奇的分割线 不知何时装过boost库的header-only库, 所以ratslam中的boost是可以编 ...

  5. MapReduce自定义类输出的内容为内存地址

    13480253104 mapreduce.KpiWritable@486a58c4 13502468823 mapreduce.KpiWritable@3de9d100 13560439658 ma ...

  6. C&plus;&plus;标准库类模板&lpar;stack&rpar;和 队列&lpar;queue&rpar;

    在C++标准库(STL)中有栈和队列的类模板,因此可以直接使用 1.栈(stack):使用栈之前,要先包含头文件 : #include<stack> stack.push(elem); / ...

  7. C&plus;&plus;标准库类模板vector

    vector是C++标准库STL中的一个重要的类模板,相当于一个更加健壮的,有很多附加能力的数组 使用vector前首先要包含头文件 #include<vector>  1.vector的 ...

  8. 非常实用全面的 C&plus;&plus;框架,库类等资源

    这次的资源涉及到了标准库.Web应用框架.人工智能.数据库.图片处理.机器学习.日志.代码分析等,C++程序员学习必备! Jason frozen : C/C++的Jason解析生成器 Jansson ...

  9. android的引用库类

    在eclipse中的项目里,有时需要外来的jar文件.添加后就可以消去程序中的红条条啦~~~~~~~~~可以照下面的说明添加. 方法/步骤   打开eclipse,导入项目   右击 项目 , “Bu ...

随机推荐

  1. 笔者的编辑语法:MarkDown

    由于博客园里的文章有很多排版不好,一大堆文字堆在一块会影响到阅读. MarkDowm:百科 Markdown 是一种轻量级标记语言,创始人为约翰·格鲁伯(John Gruber).它允许人们“使用易读 ...

  2. &lbrack;置顶&rsqb; 第二届微软CRM交流年会

    第二届微软CRM交流会将在12月14日举行,亲们要是感兴趣可以查看下面的活动详情.Jeff也是第一次参加这类活动,作为本次活动的嘉宾我为大家带来一个挺有意思的分享主题<Dynamics CRM ...

  3. 用python随机生成数据,再插入到postgresql中

    用python随机生成学生姓名,三科成绩和班级数据,再插入到postgresql中. 模块用psycopg2 random import random import psycopg2 fname=[' ...

  4. JavaScript中String对象的match&lpar;&rpar;、replace&lpar;&rpar; 配合正则表达式使用

    正则表达式由来已久,查找替换功能非常强大,但模板难记复杂. JavaScript中String对象的match().replace()这2个方法都要使用正则表达式的模板.当模板内容与字符串不相匹配时, ...

  5. js模块化开发——require&period;js的实战写法1

    关于在Require.js使用一个JS插件的问题 我需要在项目中引用一个js控件,这个控件依赖于a.js,b.js,c.js,.....n.js N多个js以及jquery及jquery-ui,各js ...

  6. CSS3学习系列之动画

    Transitions功能使用方法 在css3中,transitions功能通过将元素的某个属性从一个属性值在指定的时间内平滑过渡到另一个属性值来实现动画功能,可通过transitions属性来使用t ...

  7. CTF---Web入门第九题 FALSE

    FALSE分值:10 来源: iFurySt 难度:易 参与人数:4567人 Get Flag:2144人 答题人数:2157人 解题通过率:99% PHP代码审计 hint:sha1函数你有认真了解 ...

  8. LPC43xx SGPIO Slice 示意图

    SGPIO inverted clock qualifier Hi, With bits 6:5 of SGPIO_MUX_CFG the QUALIFIER_MODE is selected (0x ...

  9. PAT——1029&period; 旧键盘

    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及实际被输入的文字,请你列出肯定坏掉的那些键. 输入格式: 输入在2行中分别给出应该输入的文字.以及实际 ...

  10. python模块之itertools

    在循环对象和函数对象中,我们了解了循环器(iterator)的功能.循环器是对象的容器,包含有多个对象.通过调用循环器的next()方法 (__next__()方法,在Python 3.x中),循环器 ...