mport java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.jobcontrol.ControlledJob;
import org.apache.hadoop.mapreduce.lib.jobcontrol.JobControl;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

public class Driver {

public static class TokenizerMapper extends
            Mapper<Object, Text, Text, IntWritable> {
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        public void map(Object key, Text value, Context context)
                throws IOException, InterruptedException {
            StringTokenizer itr = new StringTokenizer(value.toString());
            while (itr.hasMoreTokens()) {
                word.set(itr.nextToken());
                context.write(word, one);
            }
        }
    }

public static class IntSumReducer extends
            Reducer<Text, IntWritable, Text, IntWritable> {
        private IntWritable result = new IntWritable();
        public void reduce(Text key, Iterable<IntWritable> values,
                Context context) throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable val : values) {
                sum += val.get();
            }
            result.set(sum);
            context.write(key, result);
        }
    }

public static class DependenceMapper extends
            Mapper<Object, Text, Text, Text> {
        private Text word = new Text();
        public void map(Object key, Text value, Context context)
                throws IOException, InterruptedException {
            String []sep=value.toString().split("\t");
            word.set(sep[1]+"\t"+sep[0]);
            System.out.println(value.toString());
            context.write(word,new Text(""));
        }
    }

public static class DependenceReducer extends
            Reducer<Text,Text,Text,Text> {
        public void reduce(Text key, Iterable<Text> values,
                Context context) throws IOException, InterruptedException {
            String[] sep = key.toString().split("\t");
            System.out.println( sep[0]+"++++++++="+ sep[1]);
            context.write(key,new Text(""));
        }
    }

public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        String[] otherArgs = new GenericOptionsParser(conf, args)
                .getRemainingArgs();
        if (otherArgs.length < 2) {
            System.err.println("Usage: wordcount <in> <out>");
            System.exit(2);
        }
        Job job = new Job(conf, "word count");
        //加入控制容器
        ControlledJob ctrljob1=new  ControlledJob(conf);
        ctrljob1.setJob(job);
        job.setJarByClass(Driver.class);
        job.setMapperClass(TokenizerMapper.class);
        job.setCombinerClass(IntSumReducer.class);
        job.setReducerClass(IntSumReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
//        job.waitForCompletion(true);

Configuration conf2 = new Configuration();
        Job job2 = new Job(conf2, "word count1");
         ControlledJob ctrljob2=new ControlledJob(conf);
            ctrljob2.setJob(job2);
            ctrljob2.addDependingJob(ctrljob1);
        job2.setJarByClass(Driver.class);
        job2.setMapperClass(DependenceMapper.class);
        job2.setReducerClass(DependenceReducer.class);
        job2.setOutputKeyClass(Text.class);
        job2.setOutputValueClass(Text.class);
        FileInputFormat.addInputPath(job2, new Path(otherArgs[1]));
        FileOutputFormat.setOutputPath(job2, new Path(otherArgs[2]));
    //    job2.waitForCompletion(true);
          JobControl jobCtrl=new JobControl("myctrl");
          
            //添加到总的JobControl里,进行控制
            jobCtrl.addJob(ctrljob1);
            jobCtrl.addJob(ctrljob2);
            jobCtrl.run();
            
    }
}

mapreduce 依赖组合的更多相关文章

  1. Python 入门 之 类的三大关系(依赖 / 组合/ 继承关系)

    Python 入门 之 类的三大关系(依赖 / 组合/ 继承关系) 在面向对象的中,类与类之间存在三种关系:依赖关系.组合关系.继承关系. 1.依赖关系:将一个类的类名或对象当做参数传递给另一个函数被 ...

  2. mapreduce 顺序组合

    import java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configura ...

  3. 8、Situation-Dependent Combination of Long-Term and Session-Based Preferences in Group Recommendations: An Experimental Analysis ----组推荐中基于长期和会话偏好的情景依赖组合

    一.摘要: 背景:会话组推荐系统的一个主要挑战是如何适当地利用群组成员之间的交互引起用户偏好,这可能会偏离用户的长期偏好.长期偏好和群组诱导的偏好之间的相对重要性应该根据具体的群组设置而变化. 本文: ...

  4. Hadoop官方文档翻译——MapReduce Tutorial

    MapReduce Tutorial(个人指导) Purpose(目的) Prerequisites(必备条件) Overview(综述) Inputs and Outputs(输入输出) MapRe ...

  5. [大牛翻译系列]Hadoop(5)MapReduce 排序:次排序(Secondary sort)

    4.2 排序(SORT) 在MapReduce中,排序的目的有两个: MapReduce可以通过排序将Map输出的键分组.然后每组键调用一次reduce. 在某些需要排序的特定场景中,用户可以将作业( ...

  6. 【原创】MapReduce编程系列之二元排序

    普通排序实现 普通排序的实现利用了按姓名的排序,调用了默认的对key的HashPartition函数来实现数据的分组.partition操作之后写入磁盘时会对数据进行排序操作(对一个分区内的数据作排序 ...

  7. Mapreduce执行过程分析(基于Hadoop2.4)——(一)

    1 概述 该瞅瞅MapReduce的内部运行原理了,以前只知道个皮毛,再不搞搞,不然怎么死的都不晓得.下文会以2.4版本中的WordCount这个经典例子作为分析的切入点,一步步来看里面到底是个什么情 ...

  8. 大数据技术 —— MapReduce 简介

    本文为senlie原创,转载请保留此地址:http://www.cnblogs.com/senlie/ 1.概要很多计算在概念上很直观,但由于输入数据很大,为了能在合理的时间内完成,这些计算必须分布在 ...

  9. Mapreduce运行过程分析(基于Hadoop2.4)——(一)

    1 概述 该瞅瞅MapReduce的内部执行原理了,曾经仅仅知道个皮毛,再不搞搞,不然怎么死的都不晓得.下文会以2.4版本号中的WordCount这个经典样例作为分析的切入点.一步步来看里面究竟是个什 ...

随机推荐

  1. PHP中使用CURL(三)

    对 post 提交的数据进行 http_build_query处理,然后再send出去,能实现更好的兼容性,更小的请求数据包. <?php /** * PHP发送Post数据 * @param ...

  2. Java "==" 和 "equals" 和 "" 问题

    //equals()方法出现的问题 String a="testd"; String b="testd"; String c=new String(" ...

  3. 【Loadrunner】初学Loadrunner——安装

    一.准备工作 1.下载Loadrunner可以参考网上百度得到的可以在下面这个地址下载,比较大,4G左右 http://www.genilogix.com/downloads/loadrunner/l ...

  4. linux服务器的操作禁忌

    1.linux系统是否支持开启SELINUX服务 我方linux系统的服务器不支持开启Selinux服务,如果开启了selinux服务,会导致系统异常并无法启动. 2.linux系统下能否开启NetW ...

  5. hdu 5524 二叉树找规律,二进制相关

    input n 1<=n<=1e18 output 有n个结点的满二叉树有多少个不相同结点数的子树 做法:树有h=log2(n)层,最多有2h-2种(1除外),然后再n减去u重复的即可 # ...

  6. CGridCtrl在MFC中的使用(一)

    CGridCtrl控件是开源的,可在CodePlex和CodeProject上搜索找到,是VC++中用于显示表格数据的控件.基本功能包括:表格显示,单元格的编辑,单元格颜色设置,鼠标事件的响应,单元格 ...

  7. CSS3--阴影,渐变,背景图片

    文字阴影.element{ text-shadow:1px 1px 1px #cccccc;}先右再下第一个值:右侧阴影的大小第二个值:下方阴影的大小第三个值:模糊距离(阴影从开始变淡到完全消失的距离 ...

  8. [原]innerText与innerHTML区别

    window.onload = function () {             document.getElementById('btn1').onclick = function () {    ...

  9. HIT Winter Day ACM入门

    A. Arpa’s hard exam and Mehrdad’s naive cheat 题意:统计1378^n的末尾数字 即统计8^n的末尾数字 n=0时为1 其他情况为{8,4,2,6}中的一个 ...

  10. 菜鸟认识揭开DLL木马

    相信经常玩木马的朋友们都会知道一些木马的特性,也会有自己最喜爱的木马,不过,很多朋友依然不知道近年兴起的“DLL木马”为何物.什么是“DLL木马”呢?它与一般的木马有什么不同? 一.从DLL技术说起 ...