使用分布式缓存读取文件



我在分布式缓存中存储了很多文件,每个文件对应一个用户ID。我想将对应于特定用户 id(这将是化简器的键)的特定文件附加到特定的 reduce 任务。但我无法这样做,因为我使用 configure 方法从分布式缓存中读取文件,该方法位于 reduce 类中的 reduce 方法之前。所以我无法访问reduce类的配置方法中reduce方法的键,因此不能只读取我想要的文件。请帮助我。

class reduce{
void configure(args)
{
/*I can a particular file from the Path[] here.
I want to select the  file corresponding to the key of the reduce method and pass its
contents to the reduce method. I am not able to do this as I can't access the key of 
the reduce method.*/
}
void reduce(args)
{
}

}

解决方案是在配置步骤期间将分布式缓存中的Path数组分配给类变量,如分布式缓存 javadocs 中所述。 当然,将地图代码替换为您的归约代码。

这是使用旧的API,看起来就像您的代码正在使用的那样。

 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);
   }
 }

最新更新