我有很多文件存储在分布式缓存中,每个文件都对应一个用户ID。我想将对应于特定用户ID(它将是reducer的键)的特定文件附加到特定的reduce任务。但是我无法这样做,因为我使用configure方法从分布式缓存中读取文件,该方法位于reduce类中的reduce方法之前。所以我无法在reduce类的configure方法中访问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)
{
}
}
答案 0 :(得分:1)
解决方案是在配置步骤中将DistributedCache中的Path
数组分配给类变量,如DistributedCache javadocs中所述。当然,请使用reduce代码替换地图代码。
这是使用旧的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);
}
}