1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| package com.matrix.stjoin;
import java.io.IOException; import java.util.StringTokenizer;
import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper;
public class stjoinMapper extends Mapper<Object, Text, Text, Text> {
@Override protected void map(Object key, Text value, Mapper<Object, Text, Text, Text>.Context context) throws IOException, InterruptedException { String childname = new String();
String parentname = new String();
String relationtype = new String();
StringTokenizer itr = new StringTokenizer(value.toString());
String[] values = new String[2]; System.out.println("Mapper端:"+values);
int i = 0;
while (itr.hasMoreTokens()) {
values[i] = itr.nextToken();
i++;
}
if (values[0].compareTo("child") != 0) {
childname = values[0];
parentname = values[1];
relationtype = "1";
context.write(new Text(values[1]), new Text(relationtype +
"+" + childname + "+" + parentname));
relationtype = "2";
context.write(new Text(values[0]), new Text(relationtype +
"+" + childname + "+" + parentname));
} }
}
|