本文讲述使用IntelliJ IDEA时遇到Hadoop提示input path does not exist(输入路径不存在)的解决过程。

环境:Mac OS X 10.9.5, IntelliJ IDEA 13.1.4, Hadoop 1.2.1

Hadoop放在虚拟机中,宿主机通过SSH连接,IDE和数据文件在宿主机。

这是自学Hadoop的第三天。以前做过点.NET开发,Mac、IntelliJ IDEA、Hadoop、CentOS对我而言,相当陌生。第一份Hadoop代码就遇到了问题。

以下代码摘自《Hadoop In Action》第4章第1份代码。

 public class MyJob extends Configured implements Tool {
public static class MapClass extends MapReduceBase
implements Mapper<Text, Text, Text, Text> {
@Override
public void map(Text key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
throws IOException {
output.collect(value, key);
}
} public static class Reduce extends MapReduceBase
implements Reducer<Text, Text, Text, Text> {
@Override
public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
String csv = "";
while (values.hasNext()) {
if (csv.length() > 0) {
csv += ", ";
}
csv += values.next().toString();
}
output.collect(key, new Text(csv));
}
} @Override
public int run(String[] args) throws Exception {
Configuration configuration = getConf(); JobConf job = new JobConf(configuration, MyJob.class); Path in = new Path(args[0]);
Path out = new Path(args[1]); FileInputFormat.setInputPaths(job, in);
FileOutputFormat.setOutputPath(job, out); job.setJobName("MyJob");
job.setMapperClass(MapClass.class);
job.setReducerClass(Reduce.class); job.setInputFormat(KeyValueTextInputFormat.class);
job.setOutputFormat(TextOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.set("key.value.separator.in.input.line", ","); JobClient.runJob(job); return 0;
} public static void main(String[] args) {
try {
int res = ToolRunner.run(new Configuration(), new MyJob(), args);
System.exit(res);
} catch (Exception e) {
e.printStackTrace();
}
}
}

主函数做了异常处理,其余和原书一致。

直接在IDEA中执行代码,数据文件目录和书上不同,故命令行参数和原书略有差别,如下:

/Users/michael/Desktop/Hadoop/HadoopInAction/cite75_99.txt output

IDEA的配置如图

数据文件路径如图

以上配置无拼写错误。然后,我很高兴地按下'Run MyJob.main()' ,准备等结果,继续跟着书走。

悲剧了,IDEA输出input path does not exist。输入路径是/Users/michael/IdeaProjects/Hadoop/Users/michael/Desktop/Hadoop/HadoopInAction/cite75_99.txt,这不是Working directory拼上我给的第一个参数么,怎么回事。

整份代码,就run方法中用了Path,应该是这边的问题。

在FileOutputFormat.setOutputPath(job, out);后面加上System.out.println(FileInputFormat.getInputPaths(job)[0].toUri());发现输入路径真的被合并到工作路径下了。怪不得报错呢(StackOverflow中有人说是我的数据文件没提交到Hadoop才会报这个错误)。

现在,可以判断问题是FileInputFormat.setInputPaths(job, in);导致的。进源码看看它是怎么工作的。

  /**
* Set the array of {@link Path}s as the list of inputs
* for the map-reduce job.
*
* @param conf Configuration of the job.
* @param inputPaths the {@link Path}s of the input directories/files
* for the map-reduce job.
*/
public static void setInputPaths(JobConf conf, Path... inputPaths) {
Path path = new Path(conf.getWorkingDirectory(), inputPaths[0]);
StringBuffer str = new StringBuffer(StringUtils.escapeString(path.toString()));
for(int i = 1; i < inputPaths.length;i++) {
str.append(StringUtils.COMMA_STR);
path = new Path(conf.getWorkingDirectory(), inputPaths[i]);
str.append(StringUtils.escapeString(path.toString()));
}
conf.set("mapred.input.dir", str.toString());
}

可以看到,源码第一句就是合并conf和inputPaths。 既然合并了工作路径,那就把它去掉好了。

在FileInputFormat.setInputPaths(job, in);前保存合并前结果

  Path workingDirectoryBak = job.getWorkingDirectory();

再设置为根目录

  job.setWorkingDirectory(new Path("/"));

然后在它后面设置回来

  job.setWorkingDirectory(workingDirectoryBak);

加上输出,确认操作结果

  System.out.println(FileInputFormat.getInputPaths(job)[0].toUri());

新代码如下,mac下的输入法不好用,直接中式英语写注释

 public int run(String[] args) throws Exception {
Configuration configuration = getConf(); JobConf job = new JobConf(configuration, MyJob.class); Path in = new Path(args[0]);
Path out = new Path(args[1]); // backup current directory, namely /Users/michael/IdeaProjects/Hadoop where source located
Path workingDirectoryBak = job.getWorkingDirectory();
// set to root dir
job.setWorkingDirectory(new Path("/"));
// let it combine root and input path
FileInputFormat.setInputPaths(job, in);
// set it back
job.setWorkingDirectory(workingDirectoryBak);
// print to confirm
System.out.println(FileInputFormat.getInputPaths(job)[0].toUri()); FileOutputFormat.setOutputPath(job, out); job.setJobName("MyJob");
job.setMapperClass(MapClass.class);
job.setReducerClass(Reduce.class); job.setInputFormat(KeyValueTextInputFormat.class);
job.setOutputFormat(TextOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.set("key.value.separator.in.input.line", ","); JobClient.runJob(job); return 0;
}

再试一次,正常,将近1分钟执行完,配置差就是这样。

Hadoop on Mac with IntelliJ IDEA - 1 解决input path does not exist问题的更多相关文章

  1. Hadoop on Mac with IntelliJ IDEA - 7 解决failed to report status for 600 seconds. Killing!问题

    本文讲述作业在Hadoop 1.2.1完成map后ruduce阶段遇到failed to report status for 600 seconds. Killing!问题的解决过程. 环境:Mac ...

  2. Hadoop on Mac with IntelliJ IDEA - 6 解决KeyValueTextInputFormat读取时只有key值问题

    本文讲述使用KeyValueTextInputFormat在Hadoop 0.x正常工作.Hadoop 1.2.1失效的解决过程. 环境:Mac OS X 10.9.5, IntelliJ IDEA ...

  3. Hadoop on Mac with IntelliJ IDEA - 5 解决java heap space问题

    本文讲述在CentOS 6.5中提交作业到hadoop 1.2.1于reduce阶段遇到Error: java heap space错误导致作业重新计算的解决过程.解决办法适用Linux.Mac OS ...

  4. Hadoop on Mac with IntelliJ IDEA - 3 解决MRUnit - No applicable class implementing Serialization问题

    本文讲述在IntelliJ IDEA中使用MRUnit 1.0.0测试Mapper派生类时因MapDriver.withInput(final K1 key, final V1 val)的key参数被 ...

  5. Hadoop on Mac with IntelliJ IDEA - 2 解决URI错误导致Permission denied

    本文讲述在IntelliJ IDEA中使用FileSystem.copyFromLocalFile操作Hadoop时因URI格式有误导致Permission denied的解决过程. 环境:Mac O ...

  6. Hadoop on Mac with IntelliJ IDEA - 9 解决Type mismatch in value from map问题

    修改陆喜恒. Hadoop实战(第2版)5.3排序的代码时遇到IO异常. 环境:Mac OS X 10.9.5, IntelliJ IDEA 13.1.5, Hadoop 1.2.1 异常具体信息如下 ...

  7. wordcount报错:org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist:

    Exception in thread "main" org.apache.hadoop.mapreduce.lib.input.InvalidInputException: In ...

  8. 解决Spark读取Hive分区表出现Input path does not exist的问题

    假设这里出错的表为test表. 现象 Hive读取正常,不会报错,Spark读取就会出现: org.apache.hadoop.mapred.InvalidInputException: Input ...

  9. Hadoop问题:Input path does not exist: hdfs://Master:9000/user/hadoop/input

    问题描述: org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: hdfs:/ ...

随机推荐

  1. HDU 1272 小希的迷宫 (水题)

    题意: 其实就是让你判断一个图是否为树,要求不能有孤立的点(没有这中情况),且只能有1个连通图,且边数+1=点数,且每个点都有边(不可能只有1个点出现). 思路: 有可能出现连续的4个0,也就是有测试 ...

  2. 【MySQL for Mac】在Mac终端导入&导出.sql文件

    导入 打开终端输入:(前提是已经配置过MySQL环境变量) mysql -u root -p create database name; use name; source 『将.sql文件直接拖拽至终 ...

  3. 【转】linux驱动开发的经典书籍

    原文网址:http://www.cnblogs.com/xmphoenix/archive/2012/03/27/2420044.html Linux驱动学习的最大困惑在于书籍的缺乏,市面上最常见的书 ...

  4. iOS - NSLog、UncaughtException日志保存到文件

    转:http://blog.csdn.net/marujunyy/article/details/12005767 对于真机,日志没法保存,不好分析问题.所以有必要将日志保存到应用的Docunment ...

  5. SPFile的使用

    转:http://blog.csdn.net/pclzr/article/details/7591741 SPFile对应于SharePoint对象模型中的文件,它的使用方法与SPFolder类大致相 ...

  6. HDU 5407 CRB and Candies

    题意:给一个正整数k,求lcm((k, 0), (k, 1), ..., (k, k)) 解法:在oeis上查了这个序列,得知答案即为lcm(1, 2, ..., k + 1) / (k + 1),而 ...

  7. NIS Edit&Nsis打包程序发布(安装和卸载)

    转自:http://blog.csdn.net/signjing/article/details/7855855 注意:首选得明确自己需要打包的程序,以及程序需要的dll文件,资源文件等. 1.下载N ...

  8. 修改Zabbix默认运行账户

    默认Zabbix运行的账户是Zabbix,但在自动部署的时候,Agent与Server的先后顺序不定,而且官方不建议两者使用同一个账户.   所以,解压压缩包后,进入目录: vi configure ...

  9. C 实现的算法篇

    算法的定义:算法是解决实际问题的一种精确的描述方法,目前,广泛认同的定义是:算法的模型分析的一组可行的确定的和有穷的规则 算法的五个特性:有穷性,确切性,输入,输出,可行性.目前算法的可执行的步骤非常 ...

  10. XSLT2.0实用的新功能 .(转)

    转自:http://blog.csdn.net/crystalbruce/article/details/7407631 2007年1月,W3C发布了XSLT2.0规范,2009年发布了XSLT2.1 ...