<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 2,  comments - 0,  trackbacks - 0
    main:
     1 package com.aamend.hadoop.MapReduce;
     2  
     3 import java.io.IOException;
     4  
     5 import org.apache.hadoop.conf.Configuration;
     6 import org.apache.hadoop.fs.FileSystem;
     7 import org.apache.hadoop.fs.Path;
     8 import org.apache.hadoop.io.IntWritable;
     9 import org.apache.hadoop.io.Text;
    10 import org.apache.hadoop.mapreduce.Job;
    11 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    12 import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
    13 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
    14 import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
    15  
    16 public class WordCount {
    17  
    18     public static void main(String[] args) throws IOException,
    19             InterruptedException, ClassNotFoundException {
    20  
    21         Path inputPath = new Path(args[0]);
    22         Path outputDir = new Path(args[1]);
    23  
    24         // Create configuration
    25         Configuration conf = new Configuration(true);
    26  
    27         // Create job
    28         Job job = new Job(conf, "WordCount");
    29         job.setJarByClass(WordCountMapper.class);
    30  
    31         // Setup MapReduce
    32         job.setMapperClass(WordCountMapper.class);
    33         job.setReducerClass(WordCountReducer.class);
    34         job.setNumReduceTasks(1);
    35  
    36         // Specify key / value
    37         job.setOutputKeyClass(Text.class);
    38         job.setOutputValueClass(IntWritable.class);
    39  
    40         // Input
    41         FileInputFormat.addInputPath(job, inputPath);
    42         job.setInputFormatClass(TextInputFormat.class);
    43  
    44         // Output
    45         FileOutputFormat.setOutputPath(job, outputDir);
    46         job.setOutputFormatClass(TextOutputFormat.class);
    47  
    48         // Delete output if exists
    49         FileSystem hdfs = FileSystem.get(conf);
    50         if (hdfs.exists(outputDir))
    51             hdfs.delete(outputDir, true);
    52  
    53         // Execute job
    54         int code = job.waitForCompletion(true? 0 : 1;
    55         System.exit(code);
    56  
    57     }
    58  
    59 }

    mapper class:
     1 package com.aamend.hadoop.MapReduce;
     2  
     3 import java.io.IOException;
     4  
     5 import org.apache.hadoop.io.IntWritable;
     6 import org.apache.hadoop.io.Text;
     7 import org.apache.hadoop.mapreduce.Mapper;
     8  
     9 public class WordCountMapper extends
    10         Mapper<Object, Text, Text, IntWritable> {
    11  
    12     private final IntWritable ONE = new IntWritable(1);
    13     private Text word = new Text();
    14  
    15     public void map(Object key, Text value, Context context)
    16             throws IOException, InterruptedException {
    17  
    18         String[] csv = value.toString().split(",");
    19         for (String str : csv) {
    20             word.set(str);
    21             context.write(word, ONE);
    22         }
    23     }
    24 }

    reducer class:
     1 package com.aamend.hadoop.MapReduce;
     2  
     3 import java.io.IOException;
     4  
     5 import org.apache.hadoop.io.IntWritable;
     6 import org.apache.hadoop.io.Text;
     7 import org.apache.hadoop.mapreduce.Reducer;
     8  
     9 public class WordCountReducer extends
    10         Reducer<Text, IntWritable, Text, IntWritable> {
    11  
    12     public void reduce(Text text, Iterable<IntWritable> values, Context context)
    13             throws IOException, InterruptedException {
    14         int sum = 0;
    15         for (IntWritable value : values) {
    16             sum += value.get();
    17         }
    18         context.write(text, new IntWritable(sum));
    19     }
    20 }




    posted on 2014-09-24 21:48 hqjma 閱讀(85) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 999久久久免费精品国产| 99精品视频免费| 免费观看AV片在线播放| 久久久久亚洲av无码专区导航| 免费看成人AA片无码视频吃奶| 亚洲自偷自偷在线制服| 国产免费一级高清淫曰本片| 亚洲中文字幕无码爆乳AV| a级午夜毛片免费一区二区| 国产成A人亚洲精V品无码性色| 免费在线观影网站| 91精品国产亚洲爽啪在线影院| 久久久久久精品免费免费自慰| 亚洲一区在线视频| 日本大片在线看黄a∨免费| 日本免费精品一区二区三区| 美腿丝袜亚洲综合| 男的把j放进女人下面视频免费| 亚洲精品高清久久| 国产精品久久久久久久久久免费 | 亚洲成?Ⅴ人在线观看无码| 免费无码午夜福利片 | jjzz亚洲亚洲女人| 中文字幕高清免费不卡视频| 亚洲AV无码第一区二区三区 | 在线人成精品免费视频| 亚洲人成7777影视在线观看| 性做久久久久免费看| 中文字幕成人免费高清在线 | 亚洲日韩国产精品无码av| 在线观看免费大黄网站| 伊人久久国产免费观看视频| 亚洲AV日韩AV永久无码免下载| 欧美大尺寸SUV免费| 一级特黄a免费大片| 亚洲首页在线观看| 免费人成网站7777视频| 222www免费视频| 无遮挡a级毛片免费看| 亚洲毛片在线观看| 亚洲精品成人网久久久久久 |