云计算实验报告书.doc





《云计算实验报告书.doc》由会员分享,可在线阅读,更多相关《云计算实验报告书.doc(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、.实验项目名称多表关联实验成绩实验者专业班级组别同组者实验日期201619第一部分:实验分析与设计(可加页)一、 实验内容描述(问题域描述)输入两个文件:一个代表工厂表,包含工厂名列和地址编号列;另一个代表地址表,包含地址名列和地址编号列。从输入数据中找出工厂名和地址名的对应关系,输出“工厂名地址名”表,按工厂名排序输出;数据文件自己设计样例。2、 实验基本原理与设计(包括实验方案设计,实验手段的确定,试验步骤等,用硬件逻辑或者算法描述)具体的算法实现如下:public class MTjoin public static int time = 0; /* 在map中先区分输入行属于左表还是右
2、表,然后对两列值进行分割, * 保存连接列在key值,剩余列和左右表标志在value中,最后输出 */ public static class Map extends Mapper / 实现map函数 public void map(Object key, Text value, Context context)throws IOException, InterruptedException String line = value.toString();/ 每行文件 String relationtype = new String();/ 左右表标识 / 输入文件首行,不处理 if(line.
3、contains(factoryname)=true|line.contains(addressed)= true) return; / 输入的一行预处理文本 StringTokenizer itr = new StringTokenizer(line); String mapkey = new String(); String mapvalue = new String(); int i = 0; while (itr.hasMoreTokens() / 先读取一个单词 String token = itr.nextToken(); / 判断该地址ID就把存到values0 if (toke
4、n.charAt(0)=0& token.charAt(0) 0) relationtype = 1; else relationtype = 2; continue; / 存工厂名 mapvalue += token + ; i+; / 输出左右表 context.write(new Text(mapkey), new Text(relationtype + + mapvalue); /*reduce解析map输出,将value中数据按照左右表分别保存, * 然后求出笛卡尔积,并输出。 */public static class Reduce extends Reducer / 实现redu
5、ce函数 public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException / 输出表头 if (0 = time) context.write(new Text(factoryname), new Text(addressname); time+; int factorynum = 0; String factory = new String10; int addressnum = 0; String address = new String10; I
6、terator ite = values.iterator(); while (ite.hasNext() String record = ite.next().toString(); int len = record.length(); int i = 2; if (0 = len) continue; / 取得左右表标识 char relationtype = record.charAt(0); / 左表 if (1 = relationtype) factoryfactorynum = record.substring(i); factorynum+; / 右表 if (2 = rela
7、tiontype) addressaddressnum = record.substring(i); addressnum+; / 求笛卡尔积 if (0 != factorynum & 0 != addressnum) for (int m = 0; m factorynum; m+) for (int n = 0; n addressnum; n+) / 输出结果 context.write(new Text(factorym), new Text(addressn); public static void main(String args) throws Exception Config
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算 实验 试验 报告书

限制150内