网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

学习日志---partitioner和采样器

Mapreduce中:

成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、成都网站制作、盘龙网络推广、重庆小程序开发、盘龙网络营销、盘龙企业策划、盘龙品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供盘龙建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

shuffle阶段是在map和reduce之间,可以自定义排序,自定义分区和自定义分组!

Mapreduce中,map出的数据是键值对,默认的是hashPatitionner来对map出的数据进行分区;

分区的方法还有其他几个:

RandomSampler sampler = 
                     new InputSampler.RandomSampler(0.5, 3000, 10);
IntervalSampler sampler2 = 
                    new InputSampler.IntervalSampler(0.333, 10);
SplitSampler sampler3 = 
                    new InputSampler.SplitSampler(reduceNumber);

实现和细节

public class TotalSortMR { 
      
    @SuppressWarnings("deprecation")
    public static int runTotalSortJob(String[] args) throws Exception {  
        Path inputPath = new Path(args[0]);  
        Path outputPath = new Path(args[1]);  
        Path partitionFile = new Path(args[2]);  
        int reduceNumber = Integer.parseInt(args[3]);  
          

        //三种采样器
        RandomSampler sampler = new InputSampler.RandomSampler(1, 3000, 10);
        IntervalSampler sampler2 = new InputSampler.IntervalSampler(0.333, 10);
        SplitSampler sampler3 = new InputSampler.SplitSampler(reduceNumber);
        
        //任务初始化
        Configuration conf = new Configuration();  
        Job job = Job.getInstance(conf);
        
        job.setJobName("Total-Sort");  
        job.setJarByClass(TotalSortMR.class);  
        job.setInputFormatClass(KeyValueTextInputFormat.class);  
        job.setMapOutputKeyClass(Text.class);  
        job.setMapOutputValueClass(Text.class);  
        job.setNumReduceTasks(reduceNumber);  

        //设置所有的分区类
        job.setPartitionerClass(TotalOrderPartitioner.class);  
        //分区类参考的分区文件
        TotalOrderPartitioner.setPartitionFile(conf, partitionFile);  
        //分区使用哪种采样器
        InputSampler.writePartitionFile(job, sampler); 
        
        //job的输入和输出路径
        FileInputFormat.setInputPaths(job, inputPath);  
        FileOutputFormat.setOutputPath(job, outputPath);  
        outputPath.getFileSystem(conf).delete(outputPath, true);  
          
        return job.waitForCompletion(true)? 0 : 1;
    }  
      
    public static void main(String[] args) throws Exception{  
        System.exit(runTotalSortJob(args));  
    }
}

job默认的输入格式是TextInputFormat,这个是key-value的形式,key是每行的行标,value是每行的内容。可以更改

job.setInputFormatClass(,....)

一般要设置mapper的输出格式,以备后面使用。


分享文章:学习日志---partitioner和采样器
当前地址:http://bjjierui.cn/article/psphsc.html

其他资讯