欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

6、MapReduce自定義分區(qū)實現(xiàn)-創(chuàng)新互聯(lián)

MapReduce自帶的分區(qū)器是HashPartitioner
原理:先對map輸出的key求hash值,再模上reduce task個數(shù),根據(jù)結果,決定此輸出kv對,被匹配的reduce任務取走。
6、MapReduce自定義分區(qū)實現(xiàn)
自定義分分區(qū)需要繼承Partitioner,復寫getpariton()方法
自定義分區(qū)類:
6、MapReduce自定義分區(qū)實現(xiàn)
注意:map的輸出是<K,V>鍵值對
其中int partitionIndex = dict.get(text.toString()),partitionIndex是獲取K的值

成都創(chuàng)新互聯(lián)主要業(yè)務有網站營銷策劃、成都網站制作、網站建設、微信公眾號開發(fā)、微信小程序、H5建站、程序開發(fā)等業(yè)務。一次合作終身朋友,是我們奉行的宗旨;我們不僅僅把客戶當客戶,還把客戶視為我們的合作伙伴,在開展業(yè)務的過程中,公司還積累了豐富的行業(yè)經驗、全網整合營銷推廣資源和合作伙伴關系資源,并逐漸建立起規(guī)范的客戶服務和保障體系。 

附:被計算的的文本

Dear Dear Bear Bear River Car Dear Dear  Bear Rive
Dear Dear Bear Bear River Car Dear Dear  Bear Rive

需要在main函數(shù)中設置,指定自定義分區(qū)類
6、MapReduce自定義分區(qū)實現(xiàn)
自定義分區(qū)類:

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;
import java.util.HashMap;
public class CustomPartitioner extends Partitioner<Text, IntWritable> {
    public static HashMap<String, Integer> dict = new HashMap<String, Integer>();
    //Text代表著map階段輸出的key,IntWritable代表著輸出的值
    static{
        dict.put("Dear", 0);
        dict.put("Bear", 1);
        dict.put("River", 2);
        dict.put("Car", 3);
    }
    public int getPartition(Text text, IntWritable intWritable, int i) {
        //
        int partitionIndex = dict.get(text.toString());
        return partitionIndex;
    }
}

注意:map的輸出結果是鍵值對<K,V>,int partitionIndex = dict.get(text.toString());中的partitionIndex是map輸出鍵值對中的鍵的值,也就是K的值。
Maper類:

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMap extends Mapper<LongWritable, Text, Text, IntWritable> {
    public void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String[] words = value.toString().split("\t");
        for (String word : words) {
            // 每個單詞出現(xiàn)1次,作為中間結果輸出
            context.write(new Text(word), new IntWritable(1));
        }
    }
}

Reducer類:

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class WordCountMap extends Mapper<LongWritable, Text, Text, IntWritable> {
    public void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String[] words = value.toString().split("\t");
        for (String word : words) {
            // 每個單詞出現(xiàn)1次,作為中間結果輸出
            context.write(new Text(word), new IntWritable(1));
        }
    }
}

main函數(shù):

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.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.IOException;
public class WordCountMain {
    public static void main(String[] args) throws IOException,
            ClassNotFoundException, InterruptedException {
        if (args.length != 2 || args == null) {
            System.out.println("please input Path!");
            System.exit(0);
        }
        Configuration configuration = new Configuration();
        configuration.set("mapreduce.job.jar","/home/bruce/project/kkbhdp01/target/com.kaikeba.hadoop-1.0-SNAPSHOT.jar");
        Job job = Job.getInstance(configuration, WordCountMain.class.getSimpleName());
        // 打jar包
        job.setJarByClass(WordCountMain.class);
        // 通過job設置輸入/輸出格式
        //job.setInputFormatClass(TextInputFormat.class);
        //job.setOutputFormatClass(TextOutputFormat.class);
        // 設置輸入/輸出路徑
        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        // 設置處理Map/Reduce階段的類
        job.setMapperClass(WordCountMap.class);
        //map combine
        //job.setCombinerClass(WordCountReduce.class);
        job.setReducerClass(WordCountReduce.class);
        //如果map、reduce的輸出的kv對類型一致,直接設置reduce的輸出的kv對就行;如果不一樣,需要分別設置map, reduce的輸出的kv類型
        //job.setMapOutputKeyClass(.class)
        // 設置最終輸出key/value的類型m
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        job.setPartitionerClass(CustomPartitioner.class);
        job.setNumReduceTasks(4);
        // 提交作業(yè)
        job.waitForCompletion(true);

    }
}

main函數(shù)參數(shù)設置:
6、MapReduce自定義分區(qū)實現(xiàn)

分享題目:6、MapReduce自定義分區(qū)實現(xiàn)-創(chuàng)新互聯(lián)
瀏覽地址:http://www.aaarwkj.com/article40/gceeo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供網站導航、手機網站建設、標簽優(yōu)化、品牌網站制作、微信公眾號、網站收錄

廣告

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

成都app開發(fā)公司
丁香六月婷婷激情啪啪综合 | 未满18禁止入内在线观看| 蜜臀99久久精品久久久| 日韩黄色精品中文视频| 91欧美一区二区在线视频| 国产精品大白屁股视频| 亚洲欧美日韩一区中文天国| av在线免费观看美日韩| 加勒比在线观看欧美一区| 日日骚岛国中文字幕av| 91在线观看高清免费| 久久久偷拍美女撒尿尿| 欧美精品熟妇乱黑人最大| 精品人妻一区二区三区不卡| 日韩欧美一区二区麻豆| av剧情网址在线观看| 五月综合丁香婷婷久久| 亚洲国产欧美日韩激情在线 | 欧美伦理片三级在线观看| 日韩精品中文一区二区| 亚洲成色在线综合剧情网站 | 欧美熟妇在线视频你懂的| 中文字幕女同系列av厨房| 高清av中文免费在线| 国产精品人成在线观看不卡| 中文字幕日韩精品国产| 国产第一页第二页在线| 蜜臀一二区免费在线视频| 播放欧美日韩特黄大片| 91高清国产在线播放| 国产av日韩精品一区二区三区| 亚洲精品中文字幕一二三| 日韩成人在线视频观看| 日韩经典三级精品自拍| 久久精品国产亚洲av不丁香| 丁香六月综合激情啪啪啪| 亚洲一区二区美女av| 韩国三级福利在线观看| 大龄熟妇丰满有水多毛浓| 精品色欧美色国产一区国产| 性生活自制视频网站麻豆|