mapreduce-----学生成绩(3)

数据
computer,huangxiaoming,85,86,41,75,93,42,85
computer,xuzheng,54,52,86,91,42
computer,huangbo,85,42,96,38
english,zhaobenshan,54,52,86,91,42,85,75
english,liuyifei,85,41,75,21,85,96,14
algorithm,liuyifei,75,85,62,48,54,96,15
computer,huangjiaju,85,75,86,85,85
english,liuyifei,76,95,86,74,68,74,48
english,huangdatou,48,58,67,86,15,33,85
algorithm,huanglei,76,95,86,74,68,74,48
algorithm,huangjiaju,85,75,86,85,85,74,86
computer,huangdatou,48,58,67,86,15,33,85
english,zhouqi,85,86,41,75,93,42,85,75,55,47,22
english,huangbo,85,42,96,38,55,47,22
algorithm,liutao,85,75,85,99,66
computer,huangzitao,85,86,41,75,93,42,85
math,wangbaoqiang,85,86,41,75,93,42,85
computer,liujialing,85,41,75,21,85,96,14,74,86
computer,liuyifei,75,85,62,48,54,96,15
computer,liutao,85,75,85,99,66,88,75,91
computer,huanglei,76,95,86,74,68,74,48
english,liujialing,75,85,62,48,54,96,15
math,huanglei,76,95,86,74,68,74,48
math,huangjiaju,85,75,86,85,85,74,86
math,liutao,48,58,67,86,15,33,85
english,huanglei,85,75,85,99,66,88,75,91
math,xuzheng,54,52,86,91,42,85,75
math,huangxiaoming,85,75,85,99,66,88,75,91
math,liujialing,85,86,41,75,93,42,85,75
english,huangxiaoming,85,86,41,75,93,42,85
algorithm,huangdatou,48,58,67,86,15,33,85
algorithm,huangzitao,85,86,41,75,93,42,85,75

数据说明:
字段一:课程名
字段二:学生姓名
其余字段为学生考该门课程的成绩,但字段个数不一定

需求:
求每门课程的考试人数,及平均分

代码:

package com.mr2;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
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.output.FileOutputFormat;
public class CourseThree {
    public static class MyMapper extends Mapper
    {
    	protected void map(LongWritable key,Text value,Context context) throws IOException,InterruptedException
    	{
    		**//数据样式:computer,huangxiaoming,85,32,45,32字段个数不一定**
    		String s = value.toString();
    		String[] split =s.split(",");
    		StringBuffer str = new StringBuffer();
    		for(int i = 1;i
    {
    	protected void reduce(Text k2,Iterablev2,Context context) throws IOException,InterruptedException
    	{
    	    int sum = 0;
    	    **//countone:记录人数
    	    //counttwo: 记录同一课程分数出现次数**
    	    int countone = 0;
    	    int counttwo = 0;
    		for(Text t : v2)
    		{
    			String s = t.toString();
    			String[] m = s.split(",");
    			countone++;
    			for(int i=1;i

结果:
在这里插入图片描述
为了练习在这里借用了“中琦2513“的数据和题目需求

你可能感兴趣的:(MapReduce,mapreduce练习)