0
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

我做错了什么?

4

1 回答 1

0

从您的本地 Eclipse 中,我假设集群配置的 Hadoop 配置文件(core-site.xml)不在类路径中,被捆绑到 hadoop jar 等中的那些隐藏在类路径中。

您可以通过在提交作业之前在代码中手动设置作业配置属性“fs.default.name”来修改它:

job.getConf().set('fs.default.name', "hdfs://localhost:9000");

您可能还想配置 jobtracker,这样您就不会使用本地的:

job.getConf().set('mapred.jobtracker.address', "localhost:9001");

请注意,对于您的环境或部署,主机名、端口甚至属性名称都可能不同。

或者您可以将 hadoop conf 文件夹添加到您的类路径(并确保它具有比 hadoop jar 更高的优先级)

于 2013-11-02T15:31:50.547 回答