【发布时间】:2020-07-08 02:03:43
【问题描述】:
我有一个可以在本地正确执行的 MapReduce 程序。
它在映射器类的 setup() 方法中使用一个名为 new-positions.csv 的文件来填充内存中的哈希表:
public void setup(Context context) throws IOException, InterruptedException {
newPositions = new Hashtable<String, Integer>();
File file = new File("new-positions.csv");
Scanner inputStream = new Scanner(file);
String line = null;
String firstline = inputStream.nextLine();
while(inputStream.hasNext()){
line = inputStream.nextLine();
String[] splitLine = line.split(",");
Integer id = Integer.valueOf(splitLine[0].trim());
// String firstname = splitLine[1].trim();
// String surname = splitLine[2].trim();
String[] emails = new String[4];
for (int i = 3; i < 7; i++) {
emails[i-3] = splitLine[i].trim();
}
for (String email : emails) {
if (!email.equals("")) newPositions.put(email, id);
}
// String position = splitLine[7].trim();
inputStream.close();
}
}
Java 程序已导出为可执行 JAR。 JAR 和 full-positions.csv 都保存在我们本地文件系统的同一目录中。
然后,在该目录中,我们在终端执行以下操作(我们也尝试使用 new-positions.csv 的完整路径名):
hadoop jar MR2.jar Reader2 -files new-positions.csv InputDataset OutputFolder
它执行得很好,但是当它到达映射器时,我们得到:
Error: java.io.FileNotFoundException: new-positions.csv (No such file or directory)
这个文件肯定存在于本地,而且我们肯定是在那个目录中执行的。
我们遵循 Hadoop: The Definitive Guide (4th Ed.), p. 中给出的指导。从 274 开始,看不到我们的程序和参数在结构上有何不同。
这可能与 Hadoop 配置有关吗?我们知道有一些变通方法,例如将文件复制到 HDFS,然后从那里执行,但我们需要了解为什么这个“-files”参数没有按预期工作。
编辑:下面是驱动类的一些代码,这也可能是问题的根源:
public int run(String[] args) 抛出 IOException、InterruptedException、ClassNotFoundException { if (args.length != 5) { printUsage(this, ""); 返回 1; }
Configuration config = getConf();
FileSystem fs = FileSystem.get(config);
Job job = Job.getInstance(config);
job.setJarByClass(this.getClass());
FileInputFormat.addInputPath(job, new Path(args[3]));
// Delete old output if necessary
Path outPath = new Path(args[4]);
if (fs.exists(outPath))
fs.delete(outPath, true);
FileOutputFormat.setOutputPath(job, new Path(args[4]));
job.setInputFormatClass(SequenceFileInputFormat.class);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(Text.class);
job.setMapOutputKeyClass(EdgeWritable.class);
job.setMapOutputValueClass(NullWritable.class);
job.setMapperClass(MailReaderMapper.class);
job.setReducerClass(MailReaderReducer.class);
job.setJar("MR2.jar");
boolean status = job.waitForCompletion(true);
return status ? 0 : 1;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new Reader2(), args);
System.exit(exitCode);
}
【问题讨论】: