我有两个文件需要hadoop集群访问。这两个文件分别是good.txt和bad.txt。首先,由于这两个文件都需要从不同的节点访问,我将这两个文件放在驱动程序类的分布式缓存中,如下所示
Configuration conf = new Configuration();
DistributedCache.addCacheFile(new URI("/user/training/Rakshith/good.txt"),conf);
DistributedCache.addCacheFile(new URI("/user/training/Rakshith/bad.txt"),conf);
Job job = new Job(conf);
现在,好文件和坏文件都放在分布式缓存中。我访问mapper类中的分布式缓存,如下所示
public class LetterMapper extends Mapper<LongWritable,Text,LongWritable,Text> {
private Path[]files;
@Override
protected void setup(org.apache.hadoop.mapreduce.Mapper.Context context)
throws IOException, InterruptedException {
files=DistributedCache.getLocalCacheFiles(new Configuration(context.getConfiguration()));
}
我需要检查一个单词是否出现在good.txt或bad.txt中。所以我就用这个
File file=new File(files[0].toString()); //to access good.txt
BufferedReader br=new BufferedReader(new FileReader(file));
StringBuider sb=new StringBuilder();
String input=null;
while((input=br.readLine())!=null){
sb.append(input);
}
input=sb.toString();
我应该在我的输入变量中得到好文件的内容。但我不明白。我错过什么了吗??
2条答案
按热度按时间nzkunb0c1#
@这是我的驾驶课
我的制图课是
nhjlsmyf2#
作业是否成功完成?maptask可能会失败,因为您正在此行中使用jobconf
如果你像这样改变它,它应该工作,我看不出任何问题与剩余的代码,你张贴的问题。
或者