Distribute Cached 使用

简介: 在Kettle中说到Pentaho的MapReduce要用到它,就查了一下关于它的资料,以下是从官方查到的内容,记录一下。
在Kettle中说到Pentaho的MapReduce要用到它,就查了一下关于它的资料,以下是从官方查到的内容,记录一下。
DistributedCache: 一些比较小的需要共享的文件或者jar包,我们先存到hdfs上,然后在MapReduce线程当中进行共享,直接用了。
// Setting up the cache for the application
     
     1. Copy the requisite files to the FileSystem:
     
     $ bin/hadoop fs -copyFromLocal lookup.dat /myapp/lookup.dat  
     $ bin/hadoop fs -copyFromLocal map.zip /myapp/map.zip  
     $ bin/hadoop fs -copyFromLocal mylib.jar /myapp/mylib.jar
     $ bin/hadoop fs -copyFromLocal mytar.tar /myapp/mytar.tar
     $ bin/hadoop fs -copyFromLocal mytgz.tgz /myapp/mytgz.tgz
     $ bin/hadoop fs -copyFromLocal mytargz.tar.gz /myapp/mytargz.tar.gz

     
     2. Setup the application's JobConf:
     
     JobConf job = new JobConf();
    // #lookup.dat 表示给前面的这个文件取一个别名,类似sql里面的as别名一样
     DistributedCache.addCacheFile(new URI("/myapp/lookup.dat#lookup.dat"), 
                                   job);
     DistributedCache.addCacheArchive(new URI("/myapp/map.zip", job);
     DistributedCache.addFileToClassPath(new Path("/myapp/mylib.jar"), job);
     DistributedCache.addCacheArchive(new URI("/myapp/mytar.tar", job);
     DistributedCache.addCacheArchive(new URI("/myapp/mytgz.tgz", job);
     DistributedCache.addCacheArchive(new URI("/myapp/mytargz.tar.gz", job);

     
     3. Use the cached files in the Mapper
     or Reducer:
     
     public static class MapClass extends MapReduceBase  
     implements Mapper<K, V, K, V> {
     
       private Path[] localArchives;
       private Path[] localFiles;
       
       public void configure(JobConf job) {
         // Get the cached archives/files
         localArchives = DistributedCache.getLocalCacheArchives(job);
         localFiles = DistributedCache.getLocalCacheFiles(job);
       }
       
       public void map(K key, V value, 
                       OutputCollector<K, V> output, Reporter reporter) 
       throws IOException {
         // Use data from the cached archives/files here
         // ...
         // ...
         output.collect(k, v);
       }
     }
查看代码了才知道其实它根本不是什么缓存,它只不过是在配置文件中的指定属性记录下相应的值,然后在mapreduce的时候,调用配置文件里面的属性值,然后取得需要的文件盒jar包。
目录
相关文章
A - MaratonIME stacks popcorn buckets
A - MaratonIME stacks popcorn buckets
|
算法 搜索推荐 数据库
一个有点咬文嚼字的 sorting 和 ordering
为什么排序算法的英文是 sorting 而不是 ordering。
152 0
SVN commit:remains in tree-conflict解决方案
<span style="font-size:14px">       今天提交SVN时报异常</span><span style="font-size:14px; color:rgb(255,0,0); font-family:Arial; line-height:21px">SVN commit: ……remains in tree-conflict</span><span style
3279 0
PAT (Advanced Level) Practice - 1098 Insertion or Heap Sort(25 分)
PAT (Advanced Level) Practice - 1098 Insertion or Heap Sort(25 分)
116 0
|
BI 机器学习/深度学习 人工智能
1098. Insertion or Heap Sort (25) 21'
#include #include #include using namespace std; vector a, b; //note:堆排序从1开始 void downAdjust(int low, int high...
1162 0
|
数据建模
1052. Linked List Sorting (25) 22'
#include #include #include using namespace std; /* 题目大意:对结构体进行排序 分析:建立结构体数组,按照从首地址开始的顺序(直到-1)遍历一遍整个链表, */ ...
1006 0

热门文章

最新文章