首页 > 解决方案 > MapReduce 项目的 Mapper 部分中的多个错误

问题描述

我是一个非常新手的程序员,项目合作伙伴不会编码,需要今晚到期的学校项目的帮助(已经工作了一个多星期)。我正在尝试查找包含“Fortnite”一词并拥有超过 10000 个赞的视频的所有描述(来自 https://www.kaggle.com/datasnaek/youtube-new的 YouTube 数据)。我正在从 CSV 文件访问数据,我在代码的 Mapper 部分中遇到了多个错误,并且在我解决它之前无法进一步移动。这是我的第一个 Java/MapReduce/Hadoop 项目,我只是不明白我做错了什么。

在 Windows 10 64 位上运行 Java 1.8 和 Eclipse IDE 2019-03。我的两台电脑都有同样的问题,所以我很确定这是用户错误。我已经做了一个多星期了,我无法弄清楚。

 Clean code:
 package mapreduce,project;

 import java.io.IOException;
 import java.util.StringTokenizer;
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Reducer;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
 import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
 import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 import org.apache.hadoop.fs.Path;


 public class project extends Mapper<LongWritable, Text, Text, 
 IntWritable> 
 {

  public Text description = new Text();
  private IntWritable likes = new IntWritable(); 
  @Override
  public void map(LongWritable key, Text value, Context context)

  throws IOException, InterruptedException{

    String line = value.toString();
    String str[] = line.split("\t");
    if(str.length >= 9){
        description.set(str[8]);
    }
        likes = Integer.parseInt(str[8]); 
        if (likes >= 10000) {
       context.write("Fornite", count);
        } 
    } else  {
        return; 
      StringTokenizer itr = new StringTokenizer(line);

      while(itr.hasMoreTokens()){
       String token = itr.nextToken();
       if(token.contains("Fortnite")){
       word.set("Fortnite Count");
     context.write(word, new IntWritable(1));
       }
      }



  ````````````````````````````````````````````````
  Code with Errors:

  package mapreduce.project;
   ----> (Error: Main method not found in class 
  mapreduce.project.project, please define the main method as:
  public static void main(String[] args)


  public class project extends Mapper<LongWritable, Text, Text, 
  IntWritable> 
  {

  public Text description = new Text();
  private IntWritable likes = new IntWritable(); 
  @Override


  public void map(LongWritable key, Text value, Context context)
  -----> (ERROR: This sorce attachment does not contain the source for 
  the file Mapper.class. Change Attached Source....)

  throws IOException, InterruptedException{

    String line = value.toString();
    String str[] = line.split("\t");
    if(str.length >= 9){
        description.set(str[8]);
    }

        likes = Integer.parseInt(str[8]); ----> ( ERROR: Type mismatch: 
  cannot convert from int to INTWritable)



   if (likes >= 10000) {  ----->(ERROR: the operator >= is undefined for 
   the argument type(0) IntWriteable, int)

   context.write("Fornite", count);   (ERROR------> count cannot be 
   resolved to a variable)
        } 
    } else { ----->syntax error on "else" delete this token)
        return; 
      StringTokenizer itr = new StringTokenizer(line);

      while(itr.hasMoreTokens()){ 

       String token = itr.nextToken();
       if(token.contains("Fortnite")){
       word.set("Fortnite Count");
       context.write(word, new IntWritable(1));
       }
      }








Running the YouTube data through the MapReduce program, we expect to 
obtain a list of YouTube videos that mention Fortnite in the description 
have over 10,000 views.

标签: javawindowseclipsemapreduce

解决方案


推荐阅读