实验-MapReduce编程初级实践(共6页).docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《实验-MapReduce编程初级实践(共6页).docx》由会员分享,可在线阅读,更多相关《实验-MapReduce编程初级实践(共6页).docx(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上实验3 MapReduce编程初级实践1. 实验目的1.通过实验掌握基本的MapReduce编程方法;2.掌握用MapReduce解决一些常见的数据处理问题,包括数据去重、数据排序和数据挖掘等。2. 实验平台已经配置完成的Hadoop伪分布式环境。3. 实验内容和要求1.编程实现文件合并和去重操作对于两个输入文件,即文件A和文件B,请编写MapReduce程序,对两个文件进行合并,并剔除其中重复的内容,得到一个新的输出文件C。下面是输入文件和输出文件的一个样例供参考。实验最终结果(合并的文件):代码如下:package ;import class Merge publ
2、ic static class Map extends Mapper private static Text text = new Text(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException text = value; (text, new Text(); public static class Reduce extends Reducer public void reduce(Text key, Iterable values, Contex
3、t context) throws IOException, InterruptedException (key, new Text(); public static void main(String args) throws Exception Configuration conf = new Configuration(); (, ); String otherArgs = new String input, output ; if != 2) Usage: Merge and duplicate removal ); (2); Job job = (conf, Merge and dup
4、licate removal); ; ; ; ; ; (job, new Path(otherArgs0); (job, new Path(otherArgs1); (true) ? 0 : 1); 2. 编写程序实现对输入文件的排序现在有多个输入文件,每个文件中的每行内容均为一个整数。要求读取所有文件中的整数,进行升序排序后,输出到一个新的文件中,输出的数据格式为每行两个整数,第一个数字为第二个整数的排序位次,第二个整数为原待排列的整数。下面是输入文件和输出文件的一个样例供参考。实验结果截图:代码如下:package ;import class MergeSort public static
5、 class Map extends Mapper private static IntWritable data = new IntWritable(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException String line = (); (line); (data, new IntWritable(1); public static class Reduce extends Reducer private static IntWritable
6、linenum = new IntWritable(1); public void reduce(IntWritable key, Iterable values, Context context) throws IOException, InterruptedException for (IntWritable val : values) (linenum, key); linenum = new IntWritable() + 1); public static void main(String args) throws Exception Configuration conf = new
7、 Configuration(); (, ); String otherArgs = new String input2, output2 ; /* 直接设置输入参数 */ if != 2) Usage: mergesort ); (2); Job job = (conf, mergesort); ; ; ; ; ; (job, new Path(otherArgs0); (job, new Path(otherArgs1); (true) ? 0 : 1); 3. 对给定的表格进行信息挖掘下面给出一个child-parent的表格,要求挖掘其中的父子辈关系,给出祖孙辈关系的表格。实验最后结果
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 MapReduce 编程 初级 实践
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内