ImageVerifierCode 换一换
格式:DOCX , 页数:10 ,大小:16.86KB ,
资源ID:3693748      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3693748.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(educoder平台MapReduce基础实战.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

educoder平台MapReduce基础实战.docx

1、educoder平台MapReduce基础实战MapReduce第1关:成绩统计过关代码:import java、io、IOException;import java、util、StringTokenizer;import java、io、IOException;import java、util、StringTokenizer;import org、apache、hadoop、conf、Configuration;import org、apache、hadoop、fs、Path;import org、apache、hadoop、io、*;import org、apache、hadoop、io、

2、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、;import org、apache、hadoop、mapreduce、lib、output、;import org、apache、hadoop、util、GenericOptionsParser;public class WordCount /* B

3、egin */ public static class TokenizerMapper extends Mapper private final static IntWritable one = new IntWritable(1); private Text word = new Text(); private int maxValue = 0; public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException StringTokenizer itr

4、= new StringTokenizer(value、toString(),n); while (itr、hasMoreTokens() String str = itr、nextToken()、split( ); String name = str0; one、set(Integer、parseInt(str1); word、set(name); context、write(word,one); /context、write(word,one); public static class IntSumReducer extends Reducer private IntWritable re

5、sult = new IntWritable(); public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException int maxAge = 0; int age = 0; for (IntWritable intWritable : values) maxAge = Math、max(maxAge, intWritable、get(); result、set(maxAge); context、write(key, result); public st

6、atic void main(String args) throws Exception Configuration conf = new Configuration(); Job job = new Job(conf, word count); job、setJarByClass(WordCount、class); job、setMapperClass(TokenizerMapper、class); job、setbinerClass(IntSumReducer、class); job、setReducerClass(IntSumReducer、class); job、setOutputKe

7、yClass(Text、class); job、setOutputValueClass(IntWritable、class); String inputfile = /user/test/input; String outputFile = /user/test/output/; (job, new Path(inputfile); (job, new Path(outputFile); job、waitForpletion(true); /* End */ 命令行touch file01echo Hello World Bye Worldcat file01echo Hello World

8、Bye World file01cat file01touch file02echo Hello Hadoop Goodbye Hadoop file02cat file02start-dfs、shhadoop fs -mkdir /usrhadoop fs -mkdir /usr/inputhadoop fs -ls /usr/outputhadoop fs -ls /hadoop fs -ls /usrhadoop fs -put file01 /usr/inputhadoop fs -put file02 /usr/inputhadoop fs -ls /usr/input测评MapRe

9、duce第2关:文件内容合并去重代码import java、io、IOException;import java、util、*;import org、apache、hadoop、conf、Configuration;import org、apache、hadoop、fs、Path;import org、apache、hadoop、io、*;import org、apache、hadoop、mapreduce、Job;import org、apache、hadoop、mapreduce、Mapper;import org、apache、hadoop、mapreduce、Reducer;impor

10、t org、apache、hadoop、mapreduce、lib、input、;import org、apache、hadoop、mapreduce、lib、output、;import org、apache、hadoop、util、GenericOptionsParser;public class Merge /* * param args * 对A,B两个文件进行合并,并剔除其中重复得内容,得到一个新得输出文件C */ /在这重载map函数,直接将输入中得value复制到输出数据得key上 注意在map方法中要抛出异常:throws IOException,InterruptedExce

11、ption /* Begin */ public static class Map extends Mapper protected void map(LongWritable key, Text value, Mapper、Context context) throws IOException, InterruptedException String str = value、toString(); String data = str、split( ); Text t1= new Text(data0); Text t2 = new Text(data1); context、write(t1,

12、t2); /* End */ /在这重载reduce函数,直接将输入中得key复制到输出数据得key上 注意在reduce方法上要抛出异常:throws IOException,InterruptedException /* Begin */ public static class Reduce extends Reducer protected void reduce(Text key, Iterable values, Reducer、Context context) throws IOException, InterruptedException List list = new Arra

13、yList(); for (Text text : values) String str = text、toString(); if(!list、contains(str) list、add(str); Collections、sort(list); for (String text : list) context、write(key, new Text(text); /* End */ public static void main(String args) throws Exception Configuration conf = new Configuration(); Job job

14、= new Job(conf, word count); job、setJarByClass(Merge、class); job、setMapperClass(Map、class); job、setbinerClass(Reduce、class); job、setReducerClass(Reduce、class); job、setOutputKeyClass(Text、class); job、setOutputValueClass(Text、class); String inputPath = /user/tmp/input/; /在这里设置输入路径 String outputPath =

15、/user/tmp/output/; /在这里设置输出路径 (job, new Path(inputPath); (job, new Path(outputPath); System、exit(job、waitForpletion(true) ? 0 : 1); 测评MapReduce第3关:信息挖掘 - 挖掘父子关系代码import java、io、IOException;import java、util、*;import org、apache、hadoop、conf、Configuration;import org、apache、hadoop、fs、Path;import org、apac

16、he、hadoop、io、IntWritable;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、;import org、apache、hadoop、mapreduce、lib、output、;import org、apache、hadoop、

17、util、GenericOptionsParser;public class simple_data_mining public static int time = 0; /* * param args * 输入一个child-parent得表格 * 输出一个体现grandchild-grandparent关系得表格 */ /Map将输入文件按照空格分割成child与parent,然后正序输出一次作为右表,反序输出一次作为左表,需要注意得就是在输出得value中必须加上左右表区别标志 public static class Map extends Mapper public void map(

18、Object key, Text value, Context context) throws IOException,InterruptedException/* Begin */ String child_name = new String(); String parent_name = new String(); String relation_type = new String(); String line = value、toString(); int i = 0; while(line、charAt(i) != ) i+; String values = line、substrin

19、g(0,i),line、substring(i+1); if(values0、pareTo(child) != 0) child_name = values0; parent_name = values1; relation_type = 1;/左右表区分标志 context、write(new Text(values1), new Text(relation_type+child_name+parent_name); /左表 relation_type = 2; context、write(new Text(values0), new Text(relation_type+child_nam

20、e+parent_name); /右表 /* End */ public static class Reduce extends Reducer public void reduce(Text key, Iterable values,Context context) throws IOException,InterruptedException /* Begin */ if(time = 0) /输出表头 context、write(new Text(grand_child), new Text(grand_parent); time+; int grand_child_num = 0; S

21、tring grand_child = new String10; int grand_parent_num = 0; String grand_parent= new String10; Iterator ite = values、iterator(); while(ite、hasNext() String record = ite、next()、toString(); int len = record、length(); int i = 2; if(len = 0) continue; char relation_type = record、charAt(0); String child_

22、name = new String(); String parent_name = new String(); /获取value-list中value得child while(record、charAt(i) != +) child_name = child_name + record、charAt(i); i+; i=i+1; /获取value-list中value得parent while(ilen) parent_name = parent_name+record、charAt(i); i+; /左表,取出child放入grand_child if(relation_type = 1)

23、grand_childgrand_child_num = child_name; grand_child_num+; else/右表,取出parent放入grand_parent grand_parentgrand_parent_num = parent_name; grand_parent_num+; if(grand_parent_num != 0 & grand_child_num != 0 ) for(int m = 0;mgrand_child_num;m+) for(int n=0;ngrand_parent_num;n+) context、write(new Text(grand

24、_childm), new Text(grand_parentn); /输出结果 /* End */ public static void main(String args) throws Exception / TODO Auto-generated method stub Configuration conf = new Configuration(); Job job = Job、getInstance(conf,Single table join); job、setJarByClass(simple_data_mining、class); job、setMapperClass(Map、

25、class); job、setReducerClass(Reduce、class); job、setOutputKeyClass(Text、class); job、setOutputValueClass(Text、class); String inputPath = /user/reduce/input; /设置输入路径 String outputPath = /user/reduce/output; /设置输出路径 (job, new Path(inputPath); (job, new Path(outputPath); System、exit(job、waitForpletion(true) ? 0 : 1); 测评

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

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