是通用选项-D不支持hadoop 0.20.2?

时间:2014-06-13 08:29:24

标签: hadoop mapreduce

我正在尝试使用-D generic options从控制台设置配置属性。

这是我的控制台输入:

$ hadoop jar hadoop-0.20.2/gtee.jar dd.MaxTemperature -D file.pattern=2007.* /inputdata /outputdata

但是我通过

从代码中进行了交叉验证
Configuration conf;
System.out.println(conf.get("file.pattern"));

结果是null输出。这里的问题是什么,为什么属性的值" file.pattern"不显示?任何人都可以帮助我。

谢谢

已编辑部分:

驱动程序代码:

public int run(String[] args) throws Exception {
    Job job = new Job();
    job.setJarByClass(MaxTemperature.class);
    job.setJobName("MaxTemperature");
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(URI.create(args[0]), conf);
//  System.out.println(conf.get("file.pattern"));

    if (fs.exists(new Path(args[1]))) {
        fs.delete(new Path(args[1]), true);
    }

    System.out.println(conf.get("file.pattern"));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);

    FileInputFormat.addInputPath(job, new Path(args[0]));
    FileInputFormat.setInputPathFilter(job, RegexExcludePathFilter.class);

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

    job.setMapperClass(MapMapper.class);
    job.setCombinerClass(Mapreducers.class);
    job.setReducerClass(Mapreducers.class);

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

public static void main(String[] args) throws Exception {
    int xx = ToolRunner.run(new Configuration(),new MaxTemperature(), args);
    System.exit(xx);
}

路径过滤器实现:

public static class RegexExcludePathFilter extends Configured implements
        PathFilter {
        //String pattern = "2007.[0-1]?[0-2].[0-9][0-9].txt" ;
        Configuration conf; 
        Pattern pattern;

    @Override
    public boolean accept(Path path) {
        Matcher m = pattern.matcher(path.toString());
        return m.matches();
    }

    @Override
    public void setConf(Configuration conf) {
        this.conf = conf;
        pattern = Pattern.compile(conf.get("file.pattern"));
        System.out.println(pattern);
    }

}

2 个答案:

答案 0 :(得分:1)

要确认您在版本20.2中支持-D选项,但是需要您实现Tool接口以从命令行读取变量

  Configuration conf = new Configuration(); //this is the issue
  // When implementing tool use this
   Configuration conf = this.getConf();

答案 1 :(得分:0)

你传递的是中间的空格,这不是你应该怎么做的。而是尝试:

-Dfile.pattern=2007.*