1
我正在寫2 Mapper類和Reducer的MapReduce代碼,但我不知道爲什麼我有一個減少輸出記錄= 0。 請告訴我如何解決這個問題hadoop:減少輸出記錄= 0
package reducesidejoin;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
import java.util.Iterator;
public class ReduceSideJoinReducer extends Reducer<IntWritable,
Text, IntWritable, Text> {
@Override
public void reduce(IntWritable key, Iterable<Text> values,
Context context) throws IOException, InterruptedException {
String output = null;
Text achat;
Text vins;
Text valeur2;
Text valeur1;
Iterator<Text> itr = values.iterator();
valeur1 = itr.next();
if (valeur1.charAt(0) == 1) {
vins = valeur1;
while (itr.hasNext()) {
valeur2 = itr.next();
if (valeur2.charAt(0) == 2) {
achat = valeur2;
output = vins.toString() + achat.toString();
context.write(key, new Text(output));
}
context.write(key, new Text(output));
}
} else if (valeur1.charAt(0) == 2) {
achat = valeur1;
while (itr.hasNext()) {
valeur2 = itr.next();
if (valeur2.charAt(0) == 1) {
vins = valeur2;
output = vins.toString() + achat.toString();
System.out.println(key + "," + output);
}
context.write(key, new Text(output));
}
}
}
}
請寫出乾淨的代碼,因此開發人員可以幫助你更快更好的 –
你怎麼寫'Reducer'?你可以在這裏添加Mappers的代碼嗎? – mrsrinivas