为什么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] extends Reducer { [javac] ^ [javac] symbol:class Pair
答案 0 :(得分:0)
好吧,似乎Pair
是您定义的类,因为它不是标准的Hadoop Writable类之一。
问题在于你没有导入它,正如Jon Skeet在评论中提到的那样。
但是,请记住,因为您将它用作reduce输出值,所以它也应该是一个实现Writable接口的类。