zoukankan      html  css  js  c++  java
  • MapReduce多重MR如何实现

    一、每次输出文件存在很烦人

    // 判断output文件夹是否存在,如果存在则删除  
            Path path = new Path(otherArgs[1]);// 取第1个表示输出目录参数(第0个参数是输入目录)  
            FileSystem fileSystem = path.getFileSystem(conf);// 根据path找到这个文件  
            if (fileSystem.exists(path)) {  
                fileSystem.delete(path, true);// true的意思是,就算output有东西,也一带删除  
            }  
    

    二、多重MR

        /设置第一轮MapReduce的相应处理类与输入输出  
            Job job1 = new Job(conf);  
            .
            .
            .
      
            // 定义一个临时目录,先将任务的输出结果写到临时目录中, 下一个job以临时目录为输入目录。  
            FileInputFormat.addInputPath(job1, new Path(otherArgs[0]));  
            Path tempDir = new Path("temp_"  
                    + Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));  
            FileOutputFormat.setOutputPath(job1, tempDir);  
      
            if (job1.waitForCompletion(true)) {//如果第一轮MapReduce完成再做这里的代码  
                Job job2 = new Job(conf);  
                FileInputFormat.addInputPath(job2, tempDir);  
                //设置第二轮MapReduce的相应处理类与输入输出  
                .
                .
                FileOutputFormat.setOutputPath(job2, new Path(otherArgs[1]));  
                
                FileSystem.get(conf).deleteOnExit(tempDir);//搞完删除刚刚的临时创建的输入目录  
                System.exit(job2.waitForCompletion(true) ? 0 : 1);  
            }          
    

      

  • 相关阅读:
    awk例子
    vsftp搭建
    makefile里PHONY的相关介绍
    youget帮助使用手册
    正则表达式全集
    常用的正则表达式
    基本用法
    心情
    asp.net和java
    java and asp.net
  • 原文地址:https://www.cnblogs.com/hxsyl/p/6127852.html
Copyright © 2011-2022 走看看