在hadoop经营另一份工作

时间:2011-04-14 17:42:52

标签: hadoop

我不明白如何使作业使用相同的输出目录 目录中写入不同的文件。我曾尝试过表彰 和ucommenting这一行,但它仍然无法正常工作。我得到以下内容 我发表评论的例外情况。无论如何在代码中我试图运行两个 使用相同的reducer但使用不同的mapper分隔作业。

编辑:不,一个作业的输出不是另一个作业的输入,原因 我希望它们在同一个文件夹中是因为它们是另一个地图的输入 减少我想做的工作。

FileOutputFormat.setOutputPath(job, new Path(args[1]));

11/04/14 13:33:11 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
Exception in thread "main" org.apache.hadoop.mapred.InvalidJobConfException: Output directory not set.
    at org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:120)
    at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:770)
    at org.apache.hadoop.mapreduce.Job.submit(Job.java:432)
    at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:447)
    at org.myorg.WordCount.main(WordCount.java:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:156)

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        // String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        // if (otherArgs.length != 2) {
        //   System.err.println("Usage: wordcount <in> <out>");
        //   System.exit(2);
        // }
        Job job = new Job(conf, "Job1");
        job.setJarByClass(WordCount.class);
        job.setMapperClass(Mapper1.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]));

        job.waitForCompletion(true);

        FileSystem hdfs = FileSystem.get(conf);
        Path fromPath = new Path("/user/hadoop/output/part-r-00000");
        Path toPath = new Path("/user/hadoop/output/output1");

        // renaming to output1
        boolean isRenamed = hdfs.rename(fromPath, toPath);
        if (isRenamed)
        {
            System.out.println("Renamed to /user/hadoop/output/output1!");
        }
        else
        {
            System.out.println("Not Renamed!");
        }

        job = new Job(conf, "Job2");
        job.setJarByClass(WordCount.class);
        job.setMapperClass(Mapper2.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]));


        System.exit( job.waitForCompletion(true) ? 0 : 1);
    }

在我的代码中添加以下内容会导致其他错误:

    job.setInputFormatClass(FileInputFormat.class);
    job.setOutputFormatClass(FileOutputFormat.class);

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

System.exit(job.waitForCompletion(true)?0:1);

Exception in thread "main" java.lang.RuntimeException: java.lang.InstantiationException
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
    at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:768)
    at org.apache.hadoop.mapreduce.Job.submit(Job.java:432)
    at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:447)
    at org.myorg.WordCount.main(WordCount.java:135)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:113)
    ... 9 more

2 个答案:

答案 0 :(得分:2)

您必须为第二个作业提供新的Configuration对象。 BTW为什么不使用这些方法输出格式?

  

job.setInputFormatClass(FileInputFormat.class);      job.setOutputFormatClass(FileOutputFormat.class);

这是一篇关于递归工作的博文,这与你正在做的事情完全相同 http://codingwiththomas.blogspot.com/2011/04/controlling-hadoop-job-recursion.html

编辑: 顺便说一句,你打算写入一个文件夹是什么,它是前一个工作的输出,也就是新工作的输入?这只会导致另一个异常,例如:“输出路径已经存在”。

答案 1 :(得分:0)

所有文件不需要位于同一目录中。您的第三个作业可以有多个输入路径(目录或文件)。

FileInputFormat.addInputPaths(JobConf conf, String commaSeparatedPaths)

和朋友们......

相关问题