hadoop 多job执行的三种方法

本文提供了一种方法,通过创建多个MapReduce作业并设置依赖关系,来实现一个作业的输出作为另一个作业的输入,从而生成两个不同输出文件。包括使用Cascading jobs、Two JobConf objects、ChainMapper and ChainReducer等技术实现自动化执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If you need to split your Map Reduce jar file in two jobs in order to get two different output file, one from each reducers of the two jobs.

I mean that the first job has to produce an output file that will be the input for the second job in chain.

I will provide some ways following to solve this problem, so you can execute your job one by one automationly.

 

  1. Cascading jobs

    Create the JobConf object "job1" for the first job and set all the parameters with "input" as inputdirectory and "temp" as output directory. Execute this job: JobClient.run(job1).

    Immediately below it, create the JobConf object "job2" for the second job and set all the parameters with "temp" as inputdirectory and "output" as output directory. Execute this job:JobClient.run(job2).

  2. Two JobConf objects

    Create two JobConf objects and set all the parameters in them just like (1) except that you don't use JobClient.run.

    Then create two Job objects with jobconfs as parameters:

    Job job1=new Job(jobconf1); Job job2=new Job(jobconf2);

    Using the jobControl object, you specify the job dependencies and then run the jobs:

    JobControl jbcntrl=new JobControl("jbcntrl");
    jbcntrl.addJob(job1);
    jbcntrl.addJob(job2);
    job2.addDependingJob(job1);
    jbcntrl.run();
    
  3. ChainMapper and ChainReducer

    If you need a structure somewhat like Map+ | Reduce | Map*, you can use the ChainMapper and ChainReducer classes that come with Hadoop version 0.19 and onwards. Note that in this case, you can use only one reducer but any number of mappers before or after it.

 

参考:

http://stackoverflow.com/questions/3059736/map-reduce-chainmapper-and-chainreducer

 

转载于:https://www.cnblogs.com/hengli/archive/2012/12/04/2801583.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值