• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

求大神详解,不太懂

package com.zkpk.us;


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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;


class UserMapper extends Mapper {


        protected void map(
                        LongWritable key,
                        Text value,
                        org.apache.hadoop.mapreduce.Mapper.Context context)
                        throws java.io.IOException, InterruptedException {
                IntWritable one = new IntWritable(1);
                String[] columns = value.toString().split("\t");
                if (columns != null && columns.length == 6) {


                        Text uid = new Text(columns[1]);


                        context.write(uid, one);


                }
        };
}


class UserReducer extends Reducer {
        protected void reduce(
                        Text key,
                        java.lang.Iterable values,
                        org.apache.hadoop.mapreduce.Reducer.Context context)
                        throws java.io.IOException, InterruptedException {
                int sum = 0;
                for(IntWritable value : values){
                        sum += value.get();
                }
               
                context.write(key, new IntWritable(sum));
        };
}


public class UserCount {


        /**
         * @param args
         */
        public static void main(String[] args)throws Exception {
               
                Configuration conf = new Configuration();
                Job job = new Job(conf, "UserUid");
                job.setJarByClass(UserCount.class);
               
                job.setInputFormatClass(TextInputFormat.class);
                job.setOutputFormatClass(TextOutputFormat.class);
               
                job.setMapperClass(UserMapper.class);
                job.setReducerClass(UserReducer.class);
               
                FileInputFormat.addInputPath(job, new Path(args[0]));
                FileOutputFormat.setOutputPath(job, new Path(args[1]));
               
                job.setOutputKeyClass(Text.class);
                job.setOutputValueClass(IntWritable.class);
               
                job.waitForCompletion(true);


        }


}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与3

这是hadoop的wordCount程序啊,对input文件下的文档单词分类计数,你在hadoop output 文件夹下可以看到,每个单词出现的频数

使用道具 举报

这是MapReduce程序,是Hadoop处理数据的核心。程序有三部分组成:
第一部分:Map。表示将数据进行分词处理,分隔符是制表键
第二部分:Reduce。将Map的输出进行汇总,得到最后的输出。
第三部分:主程序。将Map和Reduce组成一个任务job,来执行,数据的输入和输出都来至于HDFS。
有问题,可以再问我。呵呵

使用道具 举报

直接说 什么问题
  直接贴代码 不想看

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!