package org.apache.hadoop.examples;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.lib.aggregate.ValueAggregatorBaseDescriptor;
import org.apache.hadoop.mapred.lib.aggregate.ValueAggregatorJob;
/**
这个是hadoop的map/reduce的例子,是对例子WordCount利用系统已经实现的map/reduce类进行简化。系统已经实现的ValueAggregatorBaseDescriptor 和ValueAggregatorJob已经实现各种数据类型的求和最大值,最小值的算法。类型如下:
UniqValueCount
LongValueSum
DoubleValueSum
ValueHistogram
LongValueMax
LongValueMin
StringValueMax
StringValueMin
具体请看相关的源代码。
这个job的执行必须用-jarlibs执行,不然会报configured错误。
执行命令如下:
hadoop jar hadoop-example.jar -libjars hadoop-example.jar shakepoems.text out_aggregate_his 3 textinputformat
* This is an example Aggregated Hadoop Map/Reduce application. It reads the
* text input files, breaks each line into words and counts them. The output is
* a locally sorted list of words and the count of how often they occurred.
*
* To run: bin/hadoop jar hadoop-*-examples.jar aggregatewordcount <i>in-dir</i>
* <i>out-dir</i> <i>numOfReducers</i> textinputformat
*
*/
public class AggregateWordCount {
/*继承类ValueAggregatorBaseDescriptor */
public static class WordCountPlugInClass extends
ValueAggregatorBaseDescriptor {
@Override
public ArrayList<Entry<Text, Text>> generateKeyValPairs(Object key,
Object val) {
String countType = LONG_VALUE_SUM;//指定算法类型是long类型的求和
ArrayList<Entry<Text, Text>> retv = new ArrayList<Entry<Text, Text>>();
String line = val.toString();
StringTokenizer itr = new StringTokenizer(line);
while (itr.hasMoreTokens()) {
Entry<Text, Text> e = generateEntry(countType, itr.nextToken(), ONE);
if (e != null) {
retv.add(e);
}
}
return retv;
}
}
/**用静态类ValueAggregatorJob执行job
* The main driver for word count map/reduce program. Invoke this method to
* submit the map/reduce job.
*
* @throws IOException
* When there is communication problems with the job tracker.
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) throws IOException {
JobConf conf = ValueAggregatorJob.createValueAggregatorJob(args
, new Class[] {WordCountPlugInClass.class});
JobClient.runJob(conf);
}
}
分享到:
相关推荐
批量删除C/C++源代码注释。 内附实现源码。 目前不能支持宏注释。
去除源代码注释,去除java源代码注释.
程序源代码注释规范 可以让你的代码更规更简洁
本资源提供了一套基于Scala语言的Apache Spark源代码注释与翻译的设计源码,包含8170个文件。其中包括2245个Questionnaire文件,1297个Scala源代码文件,249个Java源代码文件,154个TXT文档,90个Python脚本文件,56...
该工具是用于清除C/C++/Java中的// 或/**/的注释。可以对文件夹操作。处理速度非常快。
LINUX内核源代码注释0.11LINUX内核源代码注释0.11LINUX内核源代码注释0.11
小米便签的源代码及详细注解,可供新学Java的同学借鉴代码风格
Linux源代码注释
linux 版本0.01 其中含源代码及内核主要代码注释
不想让非授权者查看软件源代码注释信息或者敏感信息,即使源代码被获取也无法正确理解代码的核心思想。
源程序中包含程序的详细使用说明,源代码注释非常详细,精品学习资料 python项目合集1-10,每个项目包含源程序、可执行程序。源程序中包含程序的详细使用说明,源代码注释非常详细,精品学习资料 python项目合集1-...
nginx 源代码 注释版 注释的很详细
python项目合集11-23,每个项目包含源程序、可执行程序 源程序中包含程序的详细使用说明,源代码注释非常详细,精品学习资料 python项目合集11-23,每个项目包含源程序、可执行程序 源程序中包含程序的详细使用说明...
贪吃蛇java源代码带注释,手把手让你学会写java版的贪吃蛇
C/C++源代码注释清理工具,可自动删除源代码文件中的注释语句。使用方法: RemoveComment SourceFile
双目视觉StereoBM算法OpenCV源代码注释
C类语言源代码注释去除程序 V1.0绿色
非常好的c、c++源代码注释移除工具。可对多个文件执行操作,非常简洁,方便。
基于java的开发源码-手机游戏大富翁源代码+注释.zip 基于java的开发源码-手机游戏大富翁源代码+注释.zip 基于java的开发源码-手机游戏大富翁源代码+注释.zip 基于java的开发源码-手机游戏大富翁源代码+注释.zip 基于...
邮件发送源代码,里面注释详细。适合初学者。