LazyMapReduce

本文对比了两种LazyMapReduce的实现方式,一种是通过直接创建Job实例并配置输入输出路径,另一种则是通过继承Configured类并实现Tool接口来完成。这两种方法都实现了基本的MapReduce流程,并详细展示了具体的代码实现。

两种LazyMapReduce实现方法对比:

 1 import org.apache.hadoop.conf.Configuration;
 2 import org.apache.hadoop.util.GenericOptionsParser;
 3 import org.apache.hadoop.mapreduce.Job;
 4 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
 5 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 6 import org.apache.hadoop.fs.Path;
 7 public class LazyMR {
 8     public static void main(String[] args) throws Exception{
 9         Configuration conf =new Configuration();
10         
11         String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
12         if(otherArgs.length!=2){
13             System.err.println("Usage:<in><out>");
14             System.exit(2);
15         }
16         Job job = new Job(conf,"LazyMR");
17         
18         FileInputFormat.addInputPath(job, new Path(args[0]));
19         FileOutputFormat.setOutputPath(job, new Path(args[1]));
20         
21         System.exit(job.waitForCompletion(true)? 0:1);
22             
23     }
24 
25 }
 1 import org.apache.hadoop.conf.Configuration;
 2 import org.apache.hadoop.util.ToolRunner;
 3 import org.apache.hadoop.mapreduce.Job;
 4 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
 5 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 6 import org.apache.hadoop.fs.Path;
 7 import org.apache.hadoop.util.Tool;
 8 import org.apache.hadoop.conf.Configured;
 9 
10 public class MyJob extends Configured implements Tool{
11 
12     @Override
13     public int run (String[] args) throws Exception{
14         Configuration conf = getConf();
15         
16         Job job = new Job(conf,"MyJob");
17         job.setJarByClass(MyJob.class);
18         
19         FileInputFormat.addInputPath(job, new Path(args[0]));
20         FileOutputFormat.setOutputPath(job, new Path(args[1]));
21         
22         System.exit(job.waitForCompletion(true)? 0:1);
23     
24         return 0;
25     }
26     
27     public static void main(String[] args) throws Exception{
28         int res = ToolRunner.run(new Configuration(), new MyJob(), args);
29         
30         System.exit(res);
31     }
32     
33 }

个人认为lazyMapReduce是MapReduce程序的helloword!!

转载于:https://www.cnblogs.com/goongqk/archive/2013/06/06/lazuMapReduce.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值