學(xué)習(xí)日志---partitioner和采樣器-創(chuàng)新互聯(lián)

Mapreduce中:

站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到天寧網(wǎng)站設(shè)計(jì)與天寧網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋天寧地區(qū)。

shuffle階段是在map和reduce之間,可以自定義排序,自定義分區(qū)和自定義分組!

Mapreduce中,map出的數(shù)據(jù)是鍵值對(duì),默認(rèn)的是hashPatitionner來(lái)對(duì)map出的數(shù)據(jù)進(jìn)行分區(qū);

分區(qū)的方法還有其他幾個(gè):

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

實(shí)現(xiàn)和細(xì)節(jié)

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<Text, Text> sampler = new InputSampler.RandomSampler<Text, Text>(1, 3000, 10);
        IntervalSampler<Text, Text> sampler2 = new InputSampler.IntervalSampler<Text, Text>(0.333, 10);
        SplitSampler<Text, Text> sampler3 = new InputSampler.SplitSampler<Text, Text>(reduceNumber);
        
        //任務(wù)初始化
        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);  

        //設(shè)置所有的分區(qū)類(lèi)
        job.setPartitionerClass(TotalOrderPartitioner.class);  
        //分區(qū)類(lèi)參考的分區(qū)文件
        TotalOrderPartitioner.setPartitionFile(conf, partitionFile);  
        //分區(qū)使用哪種采樣器
        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默認(rèn)的輸入格式是TextInputFormat,這個(gè)是key-value的形式,key是每行的行標(biāo),value是每行的內(nèi)容。可以更改

job.setInputFormatClass(,....)

一般要設(shè)置mapper的輸出格式,以備后面使用。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)站標(biāo)題:學(xué)習(xí)日志---partitioner和采樣器-創(chuàng)新互聯(lián)
文章起源:http://muchs.cn/article34/dppese.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、網(wǎng)站收錄、云服務(wù)器、自適應(yīng)網(wǎng)站、品牌網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)