我正在尝试运行mapreduce作业,该作业在我的机器上运行完美,但不会在另一台机器上运行。我的映射器在生产机器上输出错误。
实际输出应该类似于
1,1 M,1,1
1,1 M,2,3
1,2 M,1,1
等等
mapper输出有一些额外的值,就像这样
0 1,1 M,1,1
0 1,1 M,2,3
0 1,2 M,1,1
除了实际值(即正确的outpt,加上一些额外的错误值) 映射器代码是
public static class Map extends Mapper<LongWritable, Text, Text, Text> {
//output keys and values
private Text key_ikM = new Text();
private Text key_ikMt = new Text();
private Text outp = new Text();
private Text outpt = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
/*the input is row no, column number, value*/
String[] line = value.toString().split(",", 3);
String row_i = line[0];
String col_j = line[1];
String val_ij = line[2];
/*code to calculate max value of row_id in the dataset*/
int max_row=3;
//int max_col=5;
for(int k=1; k<=max_row; k++){
String keyM = row_i + "," + Integer.toString(k);
String value_ij = "M" + "," + col_j + "," + val_ij;
key_ikM.set(keyM);
outp.set(value_ij);
context.write(key_ikM, outp);
}
for(int i=1; i<=max_row; i++){
String keyMt = Integer.toString(i) + "," + row_i;
String value_ik = "Mt" + "," + col_j + "," + val_ij;
key_ikMt.set(keyMt);
outpt.set(value_ik);
context.write(key_ikMt, outpt); // transpose of M
}
}
}
其中row_i
,col_j
和val_ij
取自输入。
为什么要生成这些额外的0?它是由Integer.toString()创建的吗?我应该用别的吗?请帮忙。谢谢。