分布式缓存中的hadoop访问路径变量

ca1c2owp  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(536)

我正在尝试访问 Path 分布式缓存中的变量。

  1. //Job 1
  2. FileInputFormat.addInputPath(job, new Path(args[0]));
  3. FileOutputFormat.setOutputPath(job, new Path(MINMAX));
  4. //job 2
  5. FileInputFormat.addInputPath(job1, new Path(args[0]));
  6. FileOutputFormat.setOutputPath(job1, new Path(args[1]));

在驱动器中 DistributedCache.addCacheFile(new Path(MINMAX).toUri(),conf); 以及
在setup()中

  1. Path[] cacheFiles = DistributedCache.getLocalCacheFiles(conf);
  2. BufferedReader bf = new BufferedReader(new InputStreamReader(fs.open(cacheFiles[0])));

但是展示

  1. java.lang.Exception: java.lang.NullPointerException
  2. at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:354)
  3. Caused by: java.lang.NullPointerException

我做错什么了吗。
请建议。

xqkwcwgp

xqkwcwgp1#

我找到了答案

  1. //Job 1
  2. FileInputFormat.addInputPath(job, new Path(args[0]));
  3. FileOutputFormat.setOutputPath(job, new Path(MINMAX));
  4. //job 2
  5. Path prevJob = new Path(new Path(MINMAX), "part-r-[0-9]*");
  6. FileStatus [] list = fs.globStatus(prevJob);
  7. for (FileStatus status : list) {
  8. DistributedCache.addCacheFile(status.getPath().toUri(), conf);
  9. }
  10. FileInputFormat.addInputPath(job1, new Path(args[0]));
  11. FileOutputFormat.setOutputPath(job1, new Path(args[1]));

并在setup方法中访问该文件

  1. Path[] cacheFiles = DistributedCache.getLocalCacheFiles(conf);
  2. BufferedReader bf = new BufferedReader(new InputStreamReader(
  3. fs.open(cacheFiles[0])));
展开查看全部

相关问题