资源简介
一个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 立体球体的实现
相关资源
- 易语言播放器组件无缝转换(Demo2.e)
- cc2541 BLE DEMO
- stm32f030 IAP Demo(原创)
- 代码客:G-TcpServer(IOCP) 1.0 正式版及
- CListCtrlExDemo.rar
- 易语言-海康威视SDK-DEMO
- ssm框架登录注册demo
- RK3399 DEMO官方原厂 PCB 原理图以及周边
- MQTT推送Demo
- 微信小程序驾照考试题库demo完整
- 《Hadoop大数据技术》课程设计报告.
- redisson的demo
- Hadoop.in.Practice.2nd.Edition
- bootstrap demo 源码大全
- springboot+rabbitmq项目demo(亲测可正常运
- 美松打印机SDK MsPrintSDK-Demo-DLL-CShare-
- 基于pytorch的UNet_demo实现及训练自己的
- 百度API车牌识别DEMO.rar
- stm32f105-usart-DMA收发demo
- springboot+webflux+mongodb+freemarker
- springboot整合activiti完整demo
- RFID读写demo
- 以鼠标位置为中心的滑轮放大功能d
- 基于Zxing的二维码条形码扫描和生成
- 手机基站数据Demo
- iOS Swift简单Demo
- 海康摄像头+web3.0开发包SDK的demo
- 微信小程序开发视频+demo
- 海康SDK delphi demo
- SAML协议交互,实现工程Demo有注释
评论
共有 条评论