欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Hadoop如何實(shí)現(xiàn)求平均成績

這篇文章主要介紹Hadoop如何實(shí)現(xiàn)求平均成績,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供博羅網(wǎng)站建設(shè)、博羅做網(wǎng)站、博羅網(wǎng)站設(shè)計(jì)、博羅網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、博羅企業(yè)網(wǎng)站模板建站服務(wù),十多年博羅做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

 
//思路根據(jù)hadoop原理歸并相同人名,以人名為key,以各科成績?yōu)関alue容器元素,計(jì)算容器值的和,除以科目數(shù)。
public class AverageScore {
public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{
 
 private Text word = new Text();
   
 public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
   //按照行分割
  StringTokenizer line = new StringTokenizer(value.toString(),"\n");
   
   while (line.hasMoreElements()) {
      //按照空格分割
      StringTokenizer lineBlock = new StringTokenizer(line.nextToken());
   String stuName = lineBlock.nextToken();
   int stuScore = Integer.parseInt(lineBlock.nextToken());  
         word.set(stuName);
         context.write(word, new IntWritable(stuScore));
   }
 }
}
public static class IntSumReducer extends Reducer<Text,IntWritable,Text,IntWritable> {
 private IntWritable result = new IntWritable();
 public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
   int sum = 0;
   int count =0;
   while(values.iterator().hasNext()){
    sum+=values.iterator().next().get();
    count++;
   }
   int average = sum/count;
   result.set(average);
   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: wordcount <in> <out>");
   System.exit(2);
 }
 Job job = new Job(conf, "word count");
 job.setJarByClass(AverageScore.class);
 job.setMapperClass(TokenizerMapper.class);
 job.setCombinerClass(IntSumReducer.class);
 job.setReducerClass(IntSumReducer.class);
 job.setOutputKeyClass(Text.class);
 job.setOutputValueClass(IntWritable.class);
 FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
 FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
 System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

以上是“Hadoop如何實(shí)現(xiàn)求平均成績”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

分享標(biāo)題:Hadoop如何實(shí)現(xiàn)求平均成績
當(dāng)前URL:http://www.chinadenli.net/article46/piiieg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣營銷型網(wǎng)站建設(shè)App設(shè)計(jì)用戶體驗(yàn)網(wǎng)站設(shè)計(jì)云服務(wù)器

廣告

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

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)