我正在尝试访问分布式缓存中的Path
变量。
//Job 1
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(MINMAX));
//job 2
FileInputFormat.addInputPath(job1, new Path(args[0]));
FileOutputFormat.setOutputPath(job1, new Path(args[1]));
在司机
DistributedCache.addCacheFile(new Path(MINMAX).toUri(),conf);
和
在setup()
中Path[] cacheFiles = DistributedCache.getLocalCacheFiles(conf);
BufferedReader bf = new BufferedReader(new InputStreamReader(fs.open(cacheFiles[0])));
但显示
java.lang.Exception: java.lang.NullPointerException
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:354)
Caused by: java.lang.NullPointerException
我做错了什么。
请建议。
答案 0 :(得分:0)
我找到了答案
//Job 1
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(MINMAX));
//job 2
Path prevJob = new Path(new Path(MINMAX), "part-r-[0-9]*");
FileStatus [] list = fs.globStatus(prevJob);
for (FileStatus status : list) {
DistributedCache.addCacheFile(status.getPath().toUri(), conf);
}
FileInputFormat.addInputPath(job1, new Path(args[0]));
FileOutputFormat.setOutputPath(job1, new Path(args[1]));
并在Setup方法
中访问该文件Path[] cacheFiles = DistributedCache.getLocalCacheFiles(conf);
BufferedReader bf = new BufferedReader(new InputStreamReader(
fs.open(cacheFiles[0])));