亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求大神詳解,不太懂

求大神詳解,不太懂

Youruncle 2016-12-22 19:43:18
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<LongWritable, Text, Text, IntWritable> { protected void map( LongWritable key, Text value, org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, Text, IntWritable>.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<Text, IntWritable, Text, IntWritable> { protected void reduce( Text key, java.lang.Iterable<IntWritable> values, org.apache.hadoop.mapreduce.Reducer<Text, IntWritable, Text, IntWritable>.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 回答

?
gyf451

TA貢獻1條經驗 獲得超0個贊

這是hadoop的wordCount程序啊,對input文件下的文檔單詞分類計數,你在hadoop output 文件夾下可以看到,每個單詞出現的頻數

查看完整回答
反對 回復 2017-01-09
?
趙強老師

TA貢獻10條經驗 獲得超14個贊

這是MapReduce程序,是Hadoop處理數據的核心。程序有三部分組成:

第一部分:Map。表示將數據進行分詞處理,分隔符是制表鍵

第二部分:Reduce。將Map的輸出進行匯總,得到最后的輸出。

第三部分:主程序。將Map和Reduce組成一個任務job,來執行,數據的輸入和輸出都來至于HDFS。

有問題,可以再問我。呵呵

查看完整回答
反對 回復 2016-12-27
?
_白駒過隙_

TA貢獻37條經驗 獲得超15個贊

直接說 什么問題

? ? 直接貼代碼 ?不想看

查看完整回答
反對 回復 2016-12-26
  • 3 回答
  • 0 關注
  • 1433 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號