Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by mcs ( 14 years ago )
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;
//import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
//import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapreduce.Reducer;
public class Reduce1 extends Reducer<LongWritable, Text, Text, Text>{
@Override
public void reduce(LongWritable key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
System.out.println("Reduce1: bla bla");
Hashtable<Integer, String> valStrings = new Hashtable<Integer, String>();
int i = 0;
Text outputKey = new Text();
Text outputValue = new Text();
final Iterator<Text> it = values.iterator();
while (it.hasNext()) {
Text value = it.next();
for(int j=0; j<i;j++){
outputKey = value;
String[] split = value.toString().split(" "); // -> splitten am leerzeichen?
int a = Integer.parseInt(split[0]);
int a2 = Integer.parseInt(split[1]);
String[] split2 = valStrings.get(j).split(" ");
int b = Integer.parseInt(split2[0]);
int b2 = Integer.parseInt(split2[1]);
if (a < b ||(a==b && a2<b2))
outputValue = new Text(value.toString() + ", " + valStrings.get(j));
else
outputValue = new Text(valStrings.get(j) + ", " + value.toString());
System.out.println("Reduce1: " + outputKey + "- " + outputValue);
System.out.println(outputKey.getClass());
context.write(outputKey, outputValue);
System.out.println("Reduce1: " + outputKey + "- " + outputValue);
outputKey = new Text(valStrings.get(j));
context.write(outputKey, outputValue);
}
valStrings.put(i, value.toString());
i++;
}
}
}
Revise this Paste