Mapreduce:用于查找文本文件错误中数字平均值的程序

时间:2016-12-12 21:36:28

标签: java apache hadoop mapreduce

当我在PuTTY上运行此代码时,我收到此错误:

  

mapreduce线程中的异常" main" java.langjavascript:无效(0).ClassNotFoundException:GameRatings.java

我不知道该怎么做。我也不确定它是否在以前的工作中找到了数字的平均值。我试图运行它并且映射器失败了。

我该如何解决?

import java.io.IOException;

import java.util.StringTokenizer;

import org.apache.hadoop.mapreduce.*;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.IntWritable;

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 GameRatings {

public static class mapper extends Mapper<Object, Text, Text, IntWritable>{

    private final static IntWritable one = new IntWritable(1);

    private Text word = new Text();

    public void map(Object key, Text value, Context context) throws 
   IOException, InterruptedException {

     Text publisher = new Text();

     IntWritable gameRating = new IntWritable();

     String line;

     Text gameName = new Text();

     StringTokenizer itr = new StringTokenizer(value.toString(),"\n");

     while (itr.hasMoreTokens()) {

        line = itr.nextToken();

        line.split("\t");

        gameName.set(itr.nextToken());

        publisher.set(itr.nextToken());

        gameRating.set(Integer.parseInt(itr.nextToken()));

        context.write(publisher,gameRating);

      }

    }

  }

public static class reducer extends Reducer<IntWritable, Text, IntWritable,
 Text>  {

public void reduce(IntWritable key, Iterable<Text> values, Context context, 
OutputCollector<Text, IntWritable> output) throws IOException, 
InterruptedException {

         char gameRating = ' ';

         int sum = 0;

         int gameCount = 0;

         int avgRating = 0;


         for (Text value : values) {

               sum += value.get();

                 gameCount+=1;

                 String[] tokens = value.toString().split("\t");

        }
    }
}

public static void main(String[] args) throws Exception {

    Configuration conf = new Configuration();

    Job job = Job.getInstance(conf, "Average rating");

    job.setJarByClass(GameRatings.class);

    job.setMapperClass(mapper.class);

    job.setCombinerClass(reducer.class);

    job.setReducerClass(reducer.class);

    job.setOutputKeyClass(Text.class);

    job.setOutputValueClass(IntWritable.class);

    FileInputFormat.addInputPath(job, new Path(args[0]));

    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    System.exit(job.waitForCompletion(true) ? 0 : 1);
   }
}

0 个答案:

没有答案