Hadoop如何实现求平均成绩
发表于:2024-10-27 作者:千家信息网编辑
千家信息网最后更新 2024年10月27日,这篇文章主要介绍Hadoop如何实现求平均成绩,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完! //思路根据hadoop原理归并相同人名,以人名为key,以各科成绩为value容
千家信息网最后更新 2024年10月27日Hadoop如何实现求平均成绩
这篇文章主要介绍Hadoop如何实现求平均成绩,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
//思路根据hadoop原理归并相同人名,以人名为key,以各科成绩为value容器元素,计算容器值的和,除以科目数。public class AverageScore {public static class TokenizerMapper extends Mapper
public static class IntSumReducer extends Reducer{ private IntWritable result = new IntWritable();
public void reduce(Text key, Iterablevalues, 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"); 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如何实现求平均成绩"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
成绩
内容
容器
篇文章
相同
人名
价值
元素
兴趣
原理
小伙
小伙伴
思路
更多
知识
科目
空格
行业
资讯
资讯频道
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
怎样在电脑上找到网络安全密码
数据库如何精准确定时间范围
高校教师同上一堂网络安全课
中国idc网络安全
SPSS利用数据库导入数据
通过网关访问内网服务器
成都创城网络技术有限公司
把资料上传到服务器让别人下载
php输出数据库数据
软件开发的职业岗位分析报告
戴尔服务器橙色指示灯闪
服务器端提示信息 高频访问阻断
数据库中直取语句
ibm商用服务器操作系统
软件开发要具备哪些基础知识
数字化网络安全底座
天津静海凶宅数据库
爆炸服务器
windows里增加数据库
合肥数据库安全公司
我的世界开服务器收费吗
灵一网络技术有限公司
知名l2tp服务器托管公司
登录网页显示内部服务器错误
怎么安装餐饮软件数据库
软件开发的体会与心得
国内客户软件开发
边锋网络技术在深圳有吗
服务器数据中心管理
c 服务器端开发