|
Hadoop运行的job作业的时候有具体十个步骤,详细过程如下:
public>
public void main(String[] args) throws Exception {
// (1)作业,表示一次MapReduce作业,包含自定义的Mapper和Reducer
Job job = new Job(new Configuration());
// (2)处理输入文本,把每一行解析成键值对
job.setInputFormatClass(TextInputFormat.class);
// (3)指定输入文件
FileInputFormat.setInputPaths(job, "hdfs://192.168. . :9000/input");
// (4)指定job执行自定义的Mapper
job.setMapperClass(MyMapper.class);
// (5)指定Mapper输出的键值对的类型
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
// (6)分区类
job.setPartitionerClass(HashPartitioner.class);
// (7)指定job执行自定义的Reducer类
job.setReducerClass(MyReducer.class);
// (8)指定自定义的Reducer的输出键值对的类型
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
// (9)处理输出文件,把键值对写入到输出文件里
job.setOutputFormatClass(TextOutputFormat.class);
// (10)指定给job输出文件的位置,输出目录一定要存在
FileOutputFormat.setOutputPath(job, new Path("hdfs://192.168. . :9000/output"));
// (11)通知job执行,并且等待job运行结果
job.waitForCompletion(true);
}
}
|
|
|