资源简介
一个MapReduce简单程序示例 MapReduce hadoop
代码片段和文件信息
package cn.buaa.secondInvertindex;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class SencondInvertIndexWithCombiner {
public static class InvertIndexWithCombinerMap extends Mapper {
private static final String TAG=“--InvertIndexWithCombinerMap--“;
private Text valueInfo=new Text();
private Text keyInfo=new Text();
private FileSplit spliteName;
protected void map(LongWritable key Text value
Context context)
throws IOException InterruptedException {
spliteName=(FileSplit)context.getInputSplit();
String spliteFullName=spliteName.getPath().toString();
// System.out.println(spliteFullName);
int beginIndex=spliteFullName.lastIndexOf(‘/‘);
// int endIndex=spliteFullName.lastIndexOf(‘:‘);
// System.out.println(“beginloc: “+beginIndex);
String fileName=spliteName.getPath().toString().substring(beginIndex+1);
// System.out.println(fileName);
StringTokenizer st=new StringTokenizer(value.toString());
while(st.hasMoreTokens()){
String str=st.nextToken();
// keyInfo.set(str+“:“+spliteName.getPath().toString());
//Test demo
// if(“including“.equalsIgnoreCase(str)){
// System.out.println(“including loc: “+fileName);
// }
//end of Test demo
keyInfo.set(str+“:“+fileName);
valueInfo.set(“1“);
context.write(keyInfo valueInfo);
}
}
}
public static class InvertIndexWithCombinerConbiner extends Reducer{
private int interValue;
private Text keyInfo=new Text();
private Text valueInfo=new Text();
protected void reduce(Text key Iterable value
Context context)
throws IOException InterruptedException {
int sum=0;
for (Text text : value) {
sum+=Integer.parseInt(text.toString());
}
interValue=key.toString().indexOf(“:“);
keyInfo.set(key.toString().substring(0 interValue));
valueInfo.set(key.toString().substring(interValue+1)+“:“+sum);
context.write(keyInfo valueInfo);
}
}
/* public static class InvertIndexWithCombinerPartition extends HashPartitioner{
@Override
public int getPartition(Text key Text value int numReduceTasks) {
// TODO Auto-generated method stub
return super.getPartition(key value
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1472000 2012-10-23 16:05 一个MapReduce简单程序示例.ppt
文件 8799 2012-10-22 12:46 SencondInvertIndexWithCombiner.java
----------- --------- ---------- ----- ----
1480799 2
- 上一篇:三创大赛获奖作品--报告项目PPT
- 下一篇:opengl 立体球体的实现
相关资源
- SideslipDemo
- windows安装需要的Hadoop库文件
- 此demo是一个简历的app原型,
- popupwindow完美demo
- ajax异步获取数据库数据绘制Echarts图表
- CDH 内 Yarn 动态资源池配置.pdf
- listviewdemo
- Unity3D平衡类游戏--平衡小球Demo解析(
- 耀华、泰山等地磅称重demo
- CDH集群史无前例详细版搭建方式
- Hadoop完全分布式
- OpenGL 超酷三维动画DEMO
- osgi自定义控制台命令demo
- 易语言微信官方支付模块加DEMO1.65
- Laya Wechat Demo
- 百度Echarts-echarts-demo
- unity框选demo
- Spark+hadoop+mllib及相关概念与操作笔记
- unity2018 package manager引入本地包Demo
- TCP文件传输Demo
- 云计算应用实验报告
- 微信支付一元夺宝demo
- ChoosePicturesDemo.zip
- TencentLocationDemo-master
- 基于Hadoop架构的文本分类算法
- HI3559A DEMO原理图
- Hadoop安全-大数据平台隐私保护 中文完
- 全量消费大数据商圈模型实战
- 基于GMSSL的SM9签名,密钥交换,加密,
-
MediaPla
yerDemo
评论
共有 条评论