zoukankan      html  css  js  c++  java
  • mapreduce_template

    Hadoop Tutorial - YDN https://developer.yahoo.com/hadoop/tutorial/module4.html

    import java.io.IOException;
    import java.util.StringTokenizer;
    
    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.Mapper;
    import org.apache.hadoop.mapreduce.Reducer;
    import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
    import org.apache.hadoop.util.GenericOptionsParser;
    
    public class test {
    
      public static class Map extends Mapper<Object, Text, Text, IntWritable>{
        
        private IntWritable one = new IntWritable(1);
        private Text word = new Text();
          
        public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
            String inputValue=value.toString();//input
            context.write(word, one);//output
        }
      }
      
      public static class Reduce extends Reducer<Text,IntWritable,Text,Text> {
    
        private Text result = new Text("reduce");
        public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
           for (IntWritable val : values) {
                val.get();//get number
                val.toString();//get string
                val.toString().getBytes();//get byte[]
            }
          context.write(key, result);
        }
      }
    
      public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        if (otherArgs.length != 2) {
          System.err.println("Usage: <in> <out>");
          System.exit(2);
        }
        Job job = Job.getInstance(conf, "job name");
        job.setJarByClass(test.class);
        job.setMapperClass(Map.class);
        job.setCombinerClass(Reduce.class);
        job.setReducerClass(Reduce.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
      }
    }
  • 相关阅读:
    python_摘要_加密
    python_计算器
    python_选课系统
    飞行员配对方案问题 【网络流24题】
    方格取数 【网络流24题】【最小割】
    P2402 奶牛隐藏【二分】【最大流】
    P2172 [国家集训队]部落战争【最小路径覆盖】
    最小路径覆盖问题【网络流24题】
    P2057 [SHOI2007]善意的投票 / [JLOI2010]冠军调查 [最小割] [二分图]
    P2053 [SCOI2007]修车【zkw费用流】
  • 原文地址:https://www.cnblogs.com/manhua/p/3591106.html
Copyright © 2011-2022 走看看