gpt4 book ai didi

java - 使用-files参数将文件传递给Hadoop

转载 作者:行者123 更新时间:2023-12-02 21:23:32 24 4
gpt4 key购买 nike

我有一个MapReduce程序,可以在本地正确执行。

它在mapper类的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中给出的指导:权威性指南(第四版),第1页。从274开始,并且看不到我们的程序和参数在结构上如何不同。

可能与Hadoop配置有关吗?我们知道有一些解决方法,例如将文件复制到HDFS,然后从那里执行,但是我们需要了解为什么“-files”参数不能按预期工作。

编辑:以下是来自驱动程序类的一些代码,这也可能是问题的根源:

public int run(String [] args)引发IOException,InterruptedException,ClassNotFoundException {
如果(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);
}

最佳答案

假设您的“new-positions.csv”位于文件夹H:/HDP/中,那么您需要将该文件传递为:
file:///H:/HDP/new-positions.csv
您需要使用file:///限定路径,以表明它是本地文件系统路径。另外,您需要通过完全限定的路径。

这对我来说非常合适。

例如,我将本地文件myini.ini传递如下:
yarn jar hadoop-mapreduce-examples-2.4.0.2.1.5.0-2060.jar teragen -files "file:///H:/HDP/hadoop-2.4.0.2.1.5.0-2060/share/hadoop/common/myini.ini" -Dmapreduce.job.maps=10 10737418 /usr/teraout/

关于java - 使用-files参数将文件传递给Hadoop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36698215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com