1
爲什麼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的]擴展映射{ 爲[javac]^ [javac的]符號:類對 [javac的]的位置: 找不到符號 [javac的]延伸減速器{ [javac的]^ [javac的]符號:類對
那麼你有'Pair'導入嗎?您沒有在您的(縮進)代碼中顯示*任何*進口。 – 2014-11-03 17:51:44
什麼是「Pair」?我認爲Hadoop中沒有這樣的類,它擴展了Writable。所以,它應該是你已經定義的一個類,它也應該擴展Writable,因爲它被用作一個值。 – vefthym 2014-11-03 18:16:00
非常感謝您的回覆。我已經添加了import org.apache.commons.lang3.tuple。*語句(在網上瀏覽),但它是拋出錯誤,你能否建議我需要添加哪個導入語句。 – Manvi 2014-11-03 18:20:33