hadoop配置中设置布尔参数的问题

hadoop配置中设置布尔参数的问题,hadoop,Hadoop,我有以下代码: 这是司机: 我在这里设置布尔参数区分大小写 package stubs; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.DoubleWritable; import org.apache.hadoop.io.IntWritable;

我有以下代码:

这是司机: 我在这里设置布尔参数区分大小写

package stubs;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class AvgWordLength extends Configured implements Tool{

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

@Override
public int run(String[] args) throws Exception {
    // TODO Auto-generated method stub
    /*
     * Validate that two arguments were passed from the command line.
     */
    if (args.length != 2) {
      System.out.printf("Usage: AvgWordLength <input dir> <output dir>\n");
      return -1;
    }

    /*
     * Instantiate a Job object for your job's configuration. 
     */
    Job job = new Job(getConf());
    getConf().setBoolean("caseSensitive",true);
    /*
     * Specify the jar file that contains your driver, mapper, and reducer.
     * Hadoop will transfer this jar file to nodes in your cluster running 
     * mapper and reducer tasks.
     */
    job.setJarByClass(AvgWordLength.class);

    /*
     * Specify an easily-decipherable name for the job.
     * This job name will appear in reports and logs.
     */
    job.setJobName("Average Word Length");

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

    job.setMapperClass(LetterMapper.class);
    job.setReducerClass(AverageReducer.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);

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

    /*
     * TODO implement
     */

    /*
     * Start the MapReduce job and wait for it to finish.
     * If it finishes successfully, return 0. If not, return 1.
     */
    boolean success = job.waitForCompletion(true);
    return success ? 0 : 1;
}
}
不起作用

我找到了答案

以下是驱动程序的更新代码:

package stubs;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class AvgWordLength extends Configured implements Tool{

  public static void main(String[] args) throws Exception {
      Configuration conf = new Configuration();
      conf.setBoolean("caseSensitive",true);
      int exitCode = ToolRunner.run(conf, new AvgWordLength(), args);
      System.exit(exitCode);
  }

@Override
public int run(String[] args) throws Exception {
    // TODO Auto-generated method stub
    /*
     * Validate that two arguments were passed from the command line.
     */
    if (args.length != 2) {
      System.out.printf("Usage: AvgWordLength <input dir> <output dir>\n");
      return -1;
    }

    /*
     * Instantiate a Job object for your job's configuration. 
     */
    Job job = new Job(getConf());

    /*
     * Specify the jar file that contains your driver, mapper, and reducer.
     * Hadoop will transfer this jar file to nodes in your cluster running 
     * mapper and reducer tasks.
     */
    job.setJarByClass(AvgWordLength.class);

    /*
     * Specify an easily-decipherable name for the job.
     * This job name will appear in reports and logs.
     */
    job.setJobName("Average Word Length");

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

    job.setMapperClass(LetterMapper.class);
    job.setReducerClass(AverageReducer.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);

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

    /*
     * TODO implement
     */

    /*
     * Start the MapReduce job and wait for it to finish.
     * If it finishes successfully, return 0. If not, return 1.
     */
    boolean success = job.waitForCompletion(true);
    return success ? 0 : 1;
}
}
包存根;
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.conf.Configured;
导入org.apache.hadoop.fs.Path;
导入org.apache.hadoop.io.DoubleWritable;
导入org.apache.hadoop.io.IntWritable;
导入org.apache.hadoop.io.Text;
导入org.apache.hadoop.mapreduce.Job;
导入org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
导入org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
导入org.apache.hadoop.util.Tool;
导入org.apache.hadoop.util.ToolRunner;
公共类AvgWordLength扩展配置的实现工具{
公共静态void main(字符串[]args)引发异常{
Configuration conf=新配置();
conf.setBoolean(“区分大小写”,真);
int exitCode=ToolRunner.run(conf,new AvgWordLength(),args);
系统退出(退出代码);
}
@凌驾
公共int运行(字符串[]args)引发异常{
//TODO自动生成的方法存根
/*
*验证是否从命令行传递了两个参数。
*/
如果(参数长度!=2){
System.out.printf(“用法:AvgWordLength\n”);
返回-1;
}
/*
*为作业的配置实例化作业对象。
*/
Job Job=新作业(getConf());
/*
*指定包含驱动程序、映射程序和减速器的jar文件。
*Hadoop将把这个jar文件传输到集群中运行的节点
*mapper和reducer任务。
*/
job.setJarByClass(AvgWordLength.class);
/*
*为作业指定易于识别的名称。
*此作业名称将出现在报告和日志中。
*/
setJobName(“平均字长”);
setInputPaths(作业,新路径(args[0]);
setOutputPath(作业,新路径(args[1]);
job.setMapperClass(lettmapper.class);
job.setReducerClass(AverageEducer.class);
job.setMapOutputKeyClass(Text.class);
setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(DoubleWritable.class);
/*
*待办事项实施
*/
/*
*启动MapReduce作业并等待其完成。
*如果成功完成,则返回0。如果不成功,则返回1。
*/
布尔值success=job.waitForCompletion(true);
返回成功?0:1;
}
}
作业的配置必须在传递给作业的构造函数之前完成

之后的每一个变化都不被承认

getConf().setBoolean("caseSensitive",true);
package stubs;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class AvgWordLength extends Configured implements Tool{

  public static void main(String[] args) throws Exception {
      Configuration conf = new Configuration();
      conf.setBoolean("caseSensitive",true);
      int exitCode = ToolRunner.run(conf, new AvgWordLength(), args);
      System.exit(exitCode);
  }

@Override
public int run(String[] args) throws Exception {
    // TODO Auto-generated method stub
    /*
     * Validate that two arguments were passed from the command line.
     */
    if (args.length != 2) {
      System.out.printf("Usage: AvgWordLength <input dir> <output dir>\n");
      return -1;
    }

    /*
     * Instantiate a Job object for your job's configuration. 
     */
    Job job = new Job(getConf());

    /*
     * Specify the jar file that contains your driver, mapper, and reducer.
     * Hadoop will transfer this jar file to nodes in your cluster running 
     * mapper and reducer tasks.
     */
    job.setJarByClass(AvgWordLength.class);

    /*
     * Specify an easily-decipherable name for the job.
     * This job name will appear in reports and logs.
     */
    job.setJobName("Average Word Length");

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

    job.setMapperClass(LetterMapper.class);
    job.setReducerClass(AverageReducer.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.class);

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

    /*
     * TODO implement
     */

    /*
     * Start the MapReduce job and wait for it to finish.
     * If it finishes successfully, return 0. If not, return 1.
     */
    boolean success = job.waitForCompletion(true);
    return success ? 0 : 1;
}
}