Map中的Pair类减少了抛出错误



为什么Pair类在下面的代码中抛出错误

 import java.io.IOException;
 import java.util.*;
 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.input.TextInputFormat;
 import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
 import org.apache.hadoop.util.GenericOptionsParser;
 import org.apache.commons.lang3.tuple.*;
 public static class PrizeMapper extends Mapper<LongWritable, Text, Text, Pair>{
 int rating = 0;
 Text CustID;
 IntWritable r;
 Text MovieID;
 public void map(LongWritable key, Text line, Context context
                ) throws IOException, InterruptedException {
        String line1 = line.toString();
        String [] fields = line1.split(":");
        if(fields.length > 1)
             {
             String Movieid = fields[0];
             String line2 = fields[1];
             String [] splitline = line2.split(",");
             String Custid = splitline[0];
             int rate = Integer.parseInt(splitline[1]);
             r = new IntWritable(rate);
             CustID = new Text(Custid);
             MovieID = new Text(Movieid);
             // CustID.set(Custid);
             //MovieID.set(Movieid);
             context.write(MovieID,new Pair(CustID,r));
             }
             else
             {
             return;
             }
  }
}
public static class IntSumReducer extends Reducer<Text,Pair,Text,Pair> {
private IntWritable result = new IntWritable();
public void reduce(Text key, Pair values, Context context) throws IOException, InterruptedException {
    context.write(key, values);
}

错误:找不到符号[javac]扩展Mapper{[javac]^[javac]符号:类对[javac]位置:找不到符号[javac]扩展Reducer{[javac]^[javac]symbol:class Pair

好吧,Pair似乎是您定义的一个类,因为它不是标准的Hadoop可写类之一。

正如Jon Skeet在评论中提到的那样,问题是你没有导入它。

但是,请记住,由于您使用它作为reduce输出值,因此它也应该是实现可写接口的类。

相关内容

  • 没有找到相关文章

最新更新