实验3-MapReduce编程初级实践

上传人:m**** 文档编号:544788403 上传时间:2023-11-03 格式:DOCX 页数:11 大小:101.27KB
返回 下载 相关 举报
实验3-MapReduce编程初级实践_第1页
第1页 / 共11页
实验3-MapReduce编程初级实践_第2页
第2页 / 共11页
实验3-MapReduce编程初级实践_第3页
第3页 / 共11页
实验3-MapReduce编程初级实践_第4页
第4页 / 共11页
实验3-MapReduce编程初级实践_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《实验3-MapReduce编程初级实践》由会员分享,可在线阅读,更多相关《实验3-MapReduce编程初级实践(11页珍藏版)》请在金锄头文库上搜索。

1、实验3MapReduce编程初级实践1. 实验目的1.通过实验掌握基本的MapReuce编程措施;.掌握用MpReduce解决某些常用的数据解决问题,涉及数据去重、数据排序和数据挖掘等。2. 实验平台已经配备完毕的Haoop伪分布式环境。3. 实验内容和规定1.编程实现文献合并和去重操作对于两个输入文献,即文献A和文献B,请编写MRduc程序,对两个文献进行合并,并剔除其中反复的内容,得到一种新的输出文献C。下面是输入文献和输出文献的一种样例供参照。实验最后成果(合并的文献):代码如下:pkage m.Mege;imotjava.io.Exception;impot org.pache.had

2、oopcf.Confguratin;import or.apache.haoop.f.Path;ipororg.apace.hdp.io.Text;portor.aacehdoop.apredce.ob;impot org.aphe.adoo.mpreduce.Mapper;ortrace.hadoop.mapreuce.Recer;ior org.apche.haop.mapreduce.li.inp.FileIpuFom;impt og.apache.adoop.maprede.ib.ouut.FileOutputFra;pubic class Merge plic statc clas

3、extends MapprObject,Tet, Tex, Tex priatestatic Tx tex = new Tet(); pubcvoia(ct key, xt ale,Conextcontext) trsIOExcetio,nerrptedException ext= alue; context.writ(ext, new ext(); publcsatic cass euce eted Redue public id rd(Text e, Irablext valus,Cntex ontxt) hrows OExcepion, IterrupteEcepion cnx.wre(

4、y, w Tet()); pbc sai id ain(Sting ar) throws Exceion Confuraiocnf ne Conguation(); co.set(fs.deultS, hdfs:/loalhost:900); Sring thAr = newSin inpt,ouu ; i (othegh !2) Systm.err.println(Usage:Me ad dupicate reoval in ); Syte.exit(2); Jbjob =Jo.getInsace(nf, Mege ddulicat remova); jo.setJrByClss(Mrgcl

5、ass); jb.setMapperCass(Mapls); o.seteuClass(Redce.class); jb.setOttKeyCls(Tex.clss); obsetOutputVeas(Text.cla); FieInptFormat.ddIpuPath(jb, new Path(therrgs0); FileOutFratsetOutputah(job,new Path(othrArg); ystem.exit(jowatromltn(te) ?0 : 1); 2. 编写程序实现对输入文献的排序目前有多种输入文献,每个文献中的每行内容均为一种整数。规定读取所有文献中的整数,进

6、行升序排序后,输出到一种新的文献中,输出的数据格式为每行两个整数,第一种数字为第二个整数的排序位次,第二个整数为原待排列的整数。下面是输入文献和输出文献的一种样例供参照。实验成果截图:代码如下:akage com.MergSort;import av.ioIOExcepti;import orgaache.hdopon.onfguio;ipot orgaphehados.Path;mpot oapahhaoop.oInritble;imprt rg.aache.hdop.o.Tet;imporrgapachehdop.apedueJob;ip rg.pache.hop.mapredueMape

7、;importorg.ache.hdop.mpue.Reducer;port org.apachehadomapeuce.lib.inut.FieputFrma;iport rg.apac.hadoo.apedue.lib.outpt.ileOuputFormat;publc ls ereSort publicstat cl Mpextends Maperbet, ext, Intitabl, ntWrale rvtestaic IntWriale dat = new ItWritale(); publicvid ap(Ojetkey, Txt aue,Ctet cne) hrowsIExep

8、tion,nteptdEcpton Strng line = vlu.toSrn(); dataet(nteger.sent(lin); conexrite(data, new IntWiable(1)); pulic static las Rdcexteds Reducr private sai ntWitl linu =ewIntWritble(1); pblic void educe(triblekey, ItableInWritabe vues, Cntext context) throws Ixcetio, IterrptedEion for(tWrible va: valus) c

9、ntext.write(lnum, ey); lneum= ew ItWritab(inenum.et() + ); pubic sticvod min(String args) throws eption Conigurato co =newCofgurio(); confset(fdfaultFS,hdfs:/ocahost:00); Srn oterArgs = new Sng nut2, oupt2; /* 直接设立输入参数 */ i (eArgleth ! 2) Syst.errprnt(sge: meresort ); yte.ei(); Jobj = Job.getInsan(c

10、on,mrgesor); b.seJarBylss(Megeor.cas); jobstMappras(Mp.cass); job.stReduelas(Reuce.clas); b.etupueyClas(ItWtlcla); job.etOutptVluClas(nWritabe.cls); FleInpuFrmat.addInutth(job,ew ath(otherAgs0); FileOtptrmat.etOutptPath(job, nePh(otheAgs)); Stem.eit(jbwaitFromlion(true) ? :1); 3. 对给定的表格进行信息挖掘下面给出一种ildprent的表格,规定挖掘其中的父子辈关系,给出祖孙辈关系的表格。实验最后成果截图如下:代码如下:pakeom.jin;import jv.ioExcton;imprt ja.uti.*;imprt rgapache.hadoo.con.onfigra

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号