Java 通过MapReduce代码获得的平均工资

Java 通过MapReduce代码获得的平均工资,java,hadoop,Java,Hadoop,有人能帮我找出为什么在运行MapReduce代码后我得不到平均工资。 问题:计算固定员工和合同员工的平均工资 示例输入: 1个用户1个永久100 2用户2合同500 3用户3永久200 4用户4合同300 预期输出: 永久性285 合同187 我得到的输出: 永久性100 永久性200 合同500 合同300 运行作业: $hadoop jar partition.jar com.hadoop.PartitionExample 输入/分区\u example.txt输出 package com.

有人能帮我找出为什么在运行MapReduce代码后我得不到平均工资。
问题:计算固定员工和合同员工的平均工资

示例输入:
1个用户1个永久100
2用户2合同500
3用户3永久200
4用户4合同300

预期输出:
永久性285
合同187

我得到的输出:
永久性100
永久性200
合同500
合同300

运行作业: $hadoop jar partition.jar com.hadoop.PartitionExample 输入/分区\u example.txt输出

package com.hadoop;
import java.io.IOException;
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.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;


public class PartitionExample {
        public static class MapClass extends Mapper<LongWritable, Text, 
        Text, IntWritable>{

        Text outKey = new Text(); ;
        IntWritable outValue = new IntWritable();

        public void map(LongWritable key, Text value, Context context) 
        throws IOException, InterruptedException{
            String[] colmn = value.toString().split(" ");
            outKey.set(colmn[2]);           
            outValue.set(Integer.parseInt(colmn[3])); 
            context.write(outKey, outValue);
     }
}
// permanent      [100,300,200,400]
public static class ReduceClass extends Reducer<Text,IntWritable,Text, 
IntWritable>{
        IntWritable outValue = new IntWritable();
        public void Reduce(Text key, Iterable<IntWritable> value, Context 
        context) throws IOException, InterruptedException{
            int sum = 0; int count = 0; int avg ;
            //outKey.set(key);
            for (IntWritable sal:value){
                sum = sum + sal.get(); 
                count++;
            }
            avg = sum/count ;
            outValue.set(avg);
            context.write(key, outValue);
     }
 }

public static void main(String[] args) throws IOException, 
    ClassNotFoundException, InterruptedException{
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if(otherArgs.length != 2){
        System.err.println("Number of argument passed is not 2");
        System.exit(1);
    }
    Job job = new Job(conf, "My regular MapReduce job");

    job.setJarByClass(PartitionExample.class);
    job.setMapperClass(MapClass.class);
//  job.setCombinerClass(ReduceClass.class);
    job.setReducerClass(ReduceClass.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(IntWritable.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);

}
}
package com.hadoop;
导入java.io.IOException;
导入org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.fs.Path;
导入org.apache.hadoop.io.IntWritable;
导入org.apache.hadoop.io.LongWritable;
导入org.apache.hadoop.io.Text;
导入org.apache.hadoop.mapreduce.Job;
导入org.apache.hadoop.mapreduce.Mapper;
导入org.apache.hadoop.mapreduce.Reducer;
导入org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
导入org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
导入org.apache.hadoop.util.GenericOptionsParser;
公共类分区示例{
公共静态类映射器类扩展映射器{
Text outKey=新文本();
IntWritable outValue=新的IntWritable();
公共void映射(可长写键、文本值、上下文)
抛出IOException、InterruptedException{
字符串[]colmn=value.toString().split(“”);
outKey.set(colmn[2]);
set(Integer.parseInt(colmn[3]);
write(outKey,outValue);
}
}
//永久性[100300200400]
公共静态类ReduceClass扩展了Reducer{
IntWritable outValue=新的IntWritable();
public void Reduce(文本键、Iterable值、上下文
上下文)引发IOException、InterruptedException{
整数和=0;整数计数=0;整数平均值;
//outKey.set(key);
for(可写入的sal:值){
sum=sum+sal.get();
计数++;
}
平均值=总和/计数;
超出设定值(平均值);
context.write(key,outValue);
}
}
公共静态void main(字符串[]args)引发IOException,
ClassNotFoundException,InterruptedException{
Configuration conf=新配置();
String[]otherArgs=新的GenericOptionsParser(conf,args);
if(otherArgs.length!=2){
System.err.println(“传递的参数数量不是2”);
系统出口(1);
}
Job Job=新作业(conf,“我的常规MapReduce作业”);
setJarByClass(PartitionExample.class);
job.setMapperClass(MapClass.class);
//job.setCombinerClass(ReduceClass.class);
job.setReduceClass(ReduceClass.class);
job.setMapOutputKeyClass(Text.class);
setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
addInputPath(作业,新路径(其他参数[0]);
setOutputPath(作业,新路径(其他参数[1]);
系统退出(作业等待完成(真)?0:1;
}
}

我在代码中发现了错误。我可以说,这是一个非常愚蠢的错误:(
这是在ovirridden reduce函数名中。我将其从“reduce”改为“reduce”。

我在代码中发现了错误。这是一个非常愚蠢的错误,我可以说:( 它在Ovirriden reduce函数名中。我将它从“reduce”改为“reduce”