Hadoop DistributedCache を使用していますが、いくつか問題が発生しました。私の Hadoop は疑似分散モードです。
ここから、疑似分散モードで DistributedCache.getLocalCache(xx) を使用してキャッシュされたファイルを取得することがわかります。
まず、ファイルを DistributedCache に入れます。
DistributedCache.addCacheFile(new Path(
"hdfs://localhost:8022/user/administrator/myfile").toUri(),
job.getConfiguration());
その後、マッパー setup() で取得しますが、DistributedCache.getLocalCache
null を返します。キャッシュされたファイルを介して表示できます
System.out.println("Cache: "+context.getConfiguration().get("mapred.cache.files"));
そしてそれは印刷されます:
hdfs://localhost:8022/user/administrator/myfile
ここに私の疑似コードがあります:
public static class JoinMapper{
@Override
protected void setup(Context context){
Path[] cacheFiles = DistributedCache.getLocalCacheFiles(context
.getConfiguration());
System.out.println("Cache
:"+context.getConfiguration().get("mapred.cache.files"));
Path cacheFile;
if (cacheFiles != null) {}
}
}
xx....
public static void main(String[] args){
Job job = new Job(conf, "Join Test");
DistributedCache.addCacheFile(new Path("hdfs://localhost:8022/user/administrator/myfile").toUri(),
job.getConfiguration());}
タイプセッティングが下手でごめんなさい。誰か助けてください....
ところで、私は使用してURIを取得できます
URI[] uris = DistributedCache.getCacheFiles(context
.getConfiguration());
uris の戻り値: hdfs://localhost:8022/user/administrator/myfile
uriから読み込もうとすると、ファイルが見つからないという例外でエラーが発生します。