使用MapReduce分析数据.docx

上传人:b****2 文档编号:1857507 上传时间:2022-10-24 格式:DOCX 页数:15 大小:232.28KB
下载 相关 举报
使用MapReduce分析数据.docx_第1页
第1页 / 共15页
使用MapReduce分析数据.docx_第2页
第2页 / 共15页
使用MapReduce分析数据.docx_第3页
第3页 / 共15页
使用MapReduce分析数据.docx_第4页
第4页 / 共15页
使用MapReduce分析数据.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

使用MapReduce分析数据.docx

《使用MapReduce分析数据.docx》由会员分享,可在线阅读,更多相关《使用MapReduce分析数据.docx(15页珍藏版)》请在冰豆网上搜索。

使用MapReduce分析数据.docx

使用MapReduce分析数据

 

《云计算及应用》

实验报告

 

项目名称使用MapReduce分析数据

专业班级

学号

姓名

 

实验成绩:

批阅教师:

 

2016年6月3日

实验3《使用MapReduce分析数据》

实验学时:

2实验地点:

实验日期:

一、实验目的

1.掌握MapReduce的使用方法

2.学会使用MapReduce分析数据

二、实验内容

1.运行MapReduce的wordcount实例

2.使用MapReduce完成二度朋友的实验

三、实验方法

包括实验方法、原理、技术、方案等。

四、实验步骤

1.打开hadoop的各个节点

2.运行hadoop中的wordcount实例

3.编写并编译二度朋友实验的代码

4.将要处理的数据传送到hadoop中

5.运行代码处理数据。

五、实验结果

记录实验输出数据和结果。

六、实验结论

 

1.创建wordcount_in文件夹

2.创建text.txt文件用来保存要处理的数据

 

3.将要处理的文件text.txt上传到hadoop

 

4.运行hadoop-example实例

 

5查看运行的结果

 

6.编写二度朋友实验的代码

importjava.io.IOException;

importjava.util.Random;

importjava.util.Vector;

importorg.apache.hadoop.conf.Configuration;

importorg.apache.hadoop.fs.;

importorg.apache.hadoop.fs.Path;

importorg.apache.hadoop.io.Text;

importorg.apache.hadoop.mapreduce.Job;

importorg.apache.hadoop.mapreduce.Mapper;

importorg.apache.hadoop.mapreduce.Reducer;

importorg.apache.hadoop.mapreduce.lib.input.;

importorg.apache.hadoop.mapreduce.lib.output.;

importorg.apache.hadoop.util.GenericOptionsParser;

 

publicclassdeg2friend{

publicstaticclassjob1MapperextendsMapper{

privateTextjob1map_key=newText();

privateTextjob1map_value=newText();

publicvoidmap(Objectkey,Textvalue,Contextcontext)throwsIOException,InterruptedException{

Stringeachterm[]=value.toString().split(",|\t");

for(inti=1;i

if(eachterm[0].compareTo(eachterm[i])<0){

job1map_value.set(eachterm[0]+"\t"+eachterm[i]);

}

elseif(eachterm[0].compareTo(eachterm[i])>0){

job1map_value.set(eachterm[i]+"\t"+eachterm[0]);

}

job1map_key.set(eachterm[0]);

context.write(job1map_key,job1map_value);

job1map_key.set(eachterm[i]);

context.write(job1map_key,job1map_value);

}

}

}

publicstaticclassjob1ReducerextendsReducer{

privateTextjob1reduce_key=newText();

privateTextjob1reduce_value=newText();

publicvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedException{

Stringsomeperson=key.toString();

Vectorhisfriends=newVector();

for(Textval:

values){

Stringeachterm[]=val.toString().split("\t");

if(eachterm[0].equals(someperson)){

hisfriends.add(eachterm[1]);

job1reduce_value.set("deg1friend");

context.write(val,job1reduce_value);

}

elseif(eachterm[1].equals(someperson)){

hisfriends.add(eachterm[0]);

job1reduce_value.set("deg1friend");

context.write(val,job1reduce_value);

}

}

for(inti=0;i

for(intj=0;j

if(hisfriends.elementAt(i).compareTo(hisfriends.elementAt(j))<0){

job1reduce_key.set(hisfriends.elementAt(i)+"\t"+hisfriends.elementAt(j));

job1reduce_value.set("deg2friend");

context.write(job1reduce_key,job1reduce_value);

}

//elseif(hisfriends.elementAt(i).compareTo(hisfriends.elementAt(j))>0){

//job1reduce_key.set(hisfriends.elementAt(j)+"\t"+hisfriends.elementAt(i));

//}

}

}

}

}

publicstaticclassjob2MapperextendsMapper{

privateTextjob2map_key=newText();

privateTextjob2map_value=newText();

publicvoidmap(Objectkey,Textvalue,Contextcontext)throwsIOException,InterruptedException{

Stringlineterms[]=value.toString().split("\t");

if(lineterms.length==3){

job2map_key.set(lineterms[0]+"\t"+lineterms[1]);

job2map_value.set(lineterms[2]);

context.write(job2map_key,job2map_value);

}

}

}

publicstaticclassjob2ReducerextendsReducer{

privateTextjob2reducer_key=newText();

privateTextjob2reducer_value=newText();

publicvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedException{

Vectorrelationtags=newVector();

Stringdeg2friendpair=key.toString();

for(Textval:

values){

relationtags.add(val.toString());

}

booleanisadeg1friendpair=false;

booleanisadeg2friendpair=false;

intsurport=0;

for(inti=0;i

if(relationtags.elementAt(i).equals("deg1friend")){

isadeg1friendpair=true;

}elseif(relationtags.elementAt(i).equals("deg2friend")){

isadeg2friendpair=true;

surport+=1;

}

}

if((!

isadeg1friendpair)&&isadeg2friendpair){

job2reducer_key.set(String.valueOf(surport));

job2reducer_value.set(deg2friendpair);

context.write(job2reducer_key,job2reducer_value);

}

}

}

publicstaticvoidmain(String[]args)throwsException{

Configurationconf=newConfigura

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1