网站大量收购独家精品文档,联系QQ:2885784924

考试总结厦门大学数据库实验室详解.ppt

  1. 1、本文档共45页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
GenericReplicatedJoin(续) 以下代码为GenericReplicatedJoin中的Map方法。它将会根据setup方法是否将了分布式缓存的内容装载到内存的缓存中来选择行为。如果分布式缓存的内容被装载到内存中,那么map方法就将输入块的记录和内存中的缓存做连接操作。如果分布式缓存的内容没有被装载到内存中,那么map方法就将输入块的记录装载到内存中,然后在cleanup方法中使用。 protected void map(Object key, Object value, Context context) throws IOException, InterruptedException { Pair pair = readFromInputFormat(key, value); if(distributedCacheIsSmaller) { joinAndCollect(pair, context); } else { addToCache(pair);}} public void joinAndCollect(Pair p, Context context) throws IOException, InterruptedException { ListPair cached = cachedRecords.get(p.getKey()); if (cached != null) { for (Pair cp : cached) {Pair result; if(distributedCacheIsSmaller) { result = join(p, cp); } else {result =join(cp, p); } if (result != null) { context.write(result.getKey(), result.getData()); }}}} public Pair join(Pair inputSplitPair, Pair distCachePair) { StringBuilder sb = new StringBuilder(); if (inputSplitPair.getData() != null) { sb.append(inputSplitPair.getData()); } sb.append(\t); if (distCachePair.getData() != null) { sb.append(distCachePair.getData()); } return new PairText, Text( new Text(inputSplitPair.getKey().toString()), new Text(sb.toString())); } GenericReplicatedJoin(续) 当所有的记录都被传输给map方法,MapReduce将会调用cleanup方法。如果分布式缓存的内容比输入块大,连接将会在cleanup中进行。连接的对象是map函数的缓存中的输入块的记录和分布式缓存中的记录。 protected void cleanup(Context context) throws IOException, InterruptedException { if (!distributedCacheIsSmaller) { for (Path distFile : distributedCacheFiles) { File distributedCacheFile = new File(distFile.toString()); DistributedCacheFileReader reader = getDistributedCacheReader(); reader.init(distributedCacheFile); for (Pair p : (IterablePair) reader) { joinAndCollect(p, context); } reader.close(); } } } GenericReplicatedJoin(续) 最后,任务的驱动代码必须指定需要装载到分布式缓存中的文件。以下的代码可以处理一个文件,也可以处理MapReduce输入结果的一个目录。 Configuration conf = new Configuration(); FileSystem fs = smallFilePath.get

您可能关注的文档

文档评论(0)

w447750 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档