[英]Hadoop File Read
hadoop 2.2.0中的Hadoop分布式緩存Wordcount示例。 將文件復制到hdfs文件系統中,以在mapper類的設置內部使用。
protected void setup(Context context) throws IOException,InterruptedException
{
Path[] uris = DistributedCache.getLocalCacheFiles(context.getConfiguration());
cacheData=new HashMap<String, String>();
for(Path urifile: uris)
{
try
{
BufferedReader readBuffer1 = new BufferedReader(new FileReader(urifile.toString()));
String line;
while ((line=readBuffer1.readLine())!=null)
{ System.out.println("**************"+line);
cacheData.put(line,line);
}
readBuffer1.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}
內部驅動程序主類
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
if (otherArgs.length != 3)
{
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
Job job = new Job(conf, "word_count");
job.setJarByClass(WordCount.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
Path outputpath=new Path(otherArgs[1]);
outputpath.getFileSystem(conf).delete(outputpath,true);
FileOutputFormat.setOutputPath(job,outputpath);
System.out.println("CachePath****************"+otherArgs[2]);
DistributedCache.addCacheFile(new URI(otherArgs[2]),job.getConfiguration());
System.exit(job.waitForCompletion(true) ? 0 : 1);
但是得到例外
java.io.FileNotFoundException:文件:/ home / user12 / tmp / mapred / local / 1408960542382 / cache(沒有此類文件或目錄)
因此,緩存功能無法正常工作。 任何想法 ?
解決了問題。 錯誤指定了文件位置。 現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.