迭代Map和减少操作

v7pvogib  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(296)

我正在编写一个hadoop应用程序,以特定的分辨率计算Map数据。我的输入文件是一个Map的分片,根据四分片原则命名。我需要对它们进行二次采样,然后将它们缝合在一起,直到我得到一个覆盖更大区域但分辨率更低的更高级别的平铺。比如缩小谷歌Map。
目前,我的Map器子样本瓦片和我的缩小组合瓦片一个特定的水平和形式瓦片的一个级别以上。所以就这么好了。但取决于我需要哪个图块,我需要重复这些贴图并将步骤减少x倍,这是我迄今为止无法做到的。
最好的办法是什么?有没有可能不显式地将tile保存在某个temp目录中,并在这些temp目录上启动一个新的mapreduce作业,直到得到我想要的?我认为最理想的解决方案大致类似于“while(context.hasmorethanonekey()){iterate mapreduce}”。
根据答案,我现在已经编写了一个类tilejob,它扩展了job。但是,mapreduce仍然没有链接。你能告诉我我做错了什么吗?

public boolean waitForCompletion(boolean verbose) throws IOException, InterruptedException, ClassNotFoundException{

    if(desiredkeylength != currentinputkeylength-1){            
        System.out.println("In loop, setting input at " + tempout);
        String tempin = tempout;
        FileInputFormat.setInputPaths(this, tempin);            
        tempout = (output + currentinputkeylength + "/");
        FileOutputFormat.setOutputPath(this, new Path(tempout));
        System.out.println("Setting output at " + tempout);
        currentinputkeylength--;
        Configuration conf = new Configuration();
        TileJob job = new TileJob(conf);
        job.setJobName(getJobName());
        job.setUpJob(tempin, tempout, tiletogenerate, currentinputkeylength);       
         return job.waitForCompletion(verbose);

    }else{
        //desiredkeylength == currentkeylength-1
        System.out.println("In else, setting input at " + tempout);

        String tempin = tempout;
        FileInputFormat.setInputPaths(this, tempin);            
        tempout = output;
        FileOutputFormat.setOutputPath(this, new Path(tempout));
        System.out.println("Setting output at " + tempout);
        currentinputkeylength--;
        Configuration conf = new Configuration();
        TileJob job = new TileJob(conf);
        job.setJobName(getJobName());
        job.setUpJob(tempin, tempout, tiletogenerate, currentinputkeylength);
        currentinputkeylength--;

        return super.waitForCompletion(verbose);
    }   

}
fkvaft9z

fkvaft9z1#

通常,通过使用驱动程序类main方法来配置作业、配置和格式类型(输入和输出),可以启动mapreduce步骤。一旦一切就绪,main方法调用job::waitforcompletion(),它提交作业并等待作业完成,然后继续。
您可以将其中的一些逻辑封装在一个循环中,该循环反复调用job::waitforcompletion(),直到满足条件为止。可以使用计数器实现条件。将逻辑放入reduce()方法中,用键数设置或递增计数器。driver类中的循环可以从job示例获取(分布式)计数器的值,并使用该值编写while表达式。
您使用的文件位置由您决定。在这个驱动循环中,您可以更改输入和输出的文件位置,或者保持它们不变。
我应该补充一点,您应该继续在循环中创建一个新的作业和配置示例。我不知道这些对象在这种情况下是可重用的。

public static void main(String[] args) {
    int keys = 2;
    boolean completed = true;
    while (completed & (keys > 1)) {

        Job job = new Job();

            // Do all your job configuration here

        completed = job.waitForCompletion();
        if (completed) {
            keys = job.getCounter().findCounter("Total","Keys").getValue();
        }
    }

}

相关问题