内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

MapReduce編寫wordcount程序代碼實(shí)現(xiàn)

MapReduce經(jīng)典案例代碼(wordcount)

以經(jīng)典的wordcount為例,通過自定義的mapper和reducer來(lái)實(shí)現(xiàn)單詞計(jì)數(shù)

package com.fwmagic.mapreduce;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * MapReduce單詞統(tǒng)計(jì)
 */
public class WordCountDemo {

    /**
     * 自定義Mapper繼承:org.apache.hadoop.mapreduce.Mapper,實(shí)現(xiàn)map方法
     */
    public static class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

        @Override
        protected void map(LongWritable key, Text value,
                           Mapper<LongWritable, Text, Text, IntWritable>.Context context)
                throws IOException, InterruptedException {
            String[] words = value.toString().split(" ");
            for (String word : words) {
                context.write(new Text(word), new IntWritable(1));
            }
        }
    }

    /**
     * 自定義Reducer繼承:org.apache.hadoop.mapreduce.Reducer,實(shí)現(xiàn)reduce方法
     */
    public static class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
        @Override
        protected void reduce(Text key, Iterable<IntWritable> values,
                              Reducer<Text, IntWritable, Text, IntWritable>.Context context)
                throws IOException, InterruptedException {
            int count = 0;
            for (IntWritable writable : values) {
                count += writable.get();
            }
            context.write(key, new IntWritable(count));
        }
    }

    /**
     * job啟動(dòng)類,設(shè)置參數(shù)并集群中提交job
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(WordCountDemo.class);

        job.setMapperClass(WordCountMapper.class);
        job.setReducerClass(WordCountReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        FileInputFormat.setInputPaths(job, new Path("/wordcount/input"));
        FileOutputFormat.setOutputPath(job, new Path("/wordcount/output"));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }
}

集群中/wordcount/input目錄下數(shù)據(jù)內(nèi)容

MapReduce編寫wordcount程序代碼實(shí)現(xiàn)

創(chuàng)新互聯(lián)公司服務(wù)項(xiàng)目包括黃埔網(wǎng)站建設(shè)、黃埔網(wǎng)站制作、黃埔網(wǎng)頁(yè)制作以及黃埔網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,黃埔網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到黃埔省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

打包項(xiàng)目,執(zhí)行job

hadoop jar fwmagic-wordcount.jar 

執(zhí)行輸出結(jié)果

MapReduce編寫wordcount程序代碼實(shí)現(xiàn)

網(wǎng)站標(biāo)題:MapReduce編寫wordcount程序代碼實(shí)現(xiàn)
本文鏈接:http://www.rwnh.cn/article44/jdjgee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、App開發(fā)、用戶體驗(yàn)、品牌網(wǎng)站建設(shè)手機(jī)網(wǎng)站建設(shè)、做網(wǎng)站

廣告

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

營(yíng)銷型網(wǎng)站建設(shè)
大丰市| 得荣县| 和政县| 旬邑县| 公安县| 文成县| 久治县| 梅河口市| 东山县| 邢台市| 新龙县| 梨树县| 南宫市| 石柱| 灯塔市| 和林格尔县| 新晃| 牙克石市| 竹山县| 肃南| 三门县| 资源县| 盐源县| 米易县| 永平县| 宁都县| 凤山市| 团风县| 大丰市| 高阳县| 汶川县| 石棉县| 肥城市| 榆中县| 如东县| 长海县| 安国市| 鄂托克前旗| 湟源县| 新建县| 固原市|