Edit: IDE is Intellij IDEA
OS: Mac OS X Lion
Hadoop: 1.2.1
编辑:如果文件路径存在于当前文件系统位置,则此方法有效。所以问题就变成了如何在从 IDE 运行时让它与 hdfs 一起工作。
从 IDE (Intellij IDEA) 内部运行得到异常,见下文:
在程序参数中,我指定“输入输出”
当然,“输入”确实存在于 HDFS 中,其中包含数据文件。
但是代码正在尝试从本地项目文件系统位置而不是从 HDFS 访问目录。
hdfs 命令:
James-MacBook-Pro:conf james$ hadoop fs -ls input
Found 1 items
-rw-r--r-- 1 james supergroup 15 2013-11-01 07:31 /user/james/input/simple.txt
Java源代码:
public class WordCount extends Configured implements Tool {
public static void main(String[] args) throws Exception {
int res = ToolRunner.run(new Configuration(), new WordCount(), args);
System.exit(res);
}
@Override
public int run(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: hadoop jar mrjob-1.0-SNAPSHOT-job.jar"
+ " [generic options] <in> <out>");
System.out.println();
ToolRunner.printGenericCommandUsage(System.err);
return 1;
}
Job job = new Job(getConf(), "WordCount");
job.setJarByClass(getClass());
job.setMapperClass(TokenizingMapper.class);
job.setCombinerClass(IntSumReducer.class);
job.setReducerClass(IntSumReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
boolean success = job.waitForCompletion(true);
return success ? 0 : 1;
}
}
配置:
核心站点.xml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
mapred-site.xml
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>
IDE 中的参数:
input output
例外:
Nov 03, 2013 9:46:00 AM org.apache.hadoop.security.UserGroupInformation doAs
SEVERE: PriviledgedActionException as:james cause:org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: file:/Users/james/work/projects/hadoop/mrjob/input
Exception in thread "main" org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: file:/Users/james/work/projects/hadoop/mrjob/input
我做错了什么?