INPUT:表a:userID,user.location;表b:userID,coments.votes
OUTPUT:userID,user.location,coments.votes
joinMapper:
public static class joinAMapper extends Mapper<Object,Text,Text,Text>{
private Text outKey = new Text();
private Text outValue = new Text();
public void map(Object key,Text value,Context context){
StringTokenizer itr = new StringTokenizer(value.toString());
while(itr.hasMoreTokens()){
String[] info = itr.splite(",");
outKey.set(info[0]);
outValue.set("A"+info[1]);
context.write(outKey,outValue);
}
}
}
public static class joinBMapper extends Mapper<Object,Text,Text,Text>{
private Text outKey = new Text();
private Text outValue = new Text();
public void map(Object key,Text value,Context context){
StringTokenizer itr = new StringTokenizer(value.toString());
while(itr.hasMoreTokens()){
String[] info = itr.splite(",");
outKey.set(info[0]);
outValue.set("B"+info[1]);
context.write(outKey,outValue);
}
}
}
joinReducer:
public static class joinReducer extends Reducer<Text,Text,Text,Text>{
private Text tmp = new Text();
private ArrayList<Text> listA = new ArrayList<Text>();
private ArrayList<Text> listB = new ArrayList<Text>();
public void reduce(Text text,Iterable<Text> values,Context context){
while(values.hasNext()){
tmp = values.next();
if(tmp.charAt(0)=='A'){
listA.add(tmp.subString(1));
}else if(tmp.charAt(0)=='B'){
listB.add(tmp.subString(1));
}
}
execute.JoinLogic(context);
}
}
MapReduce之连接模式一:reduce端连接
最新推荐文章于 2023-07-18 16:09:27 发布