mapreduce 中单表关联的问题
我写个一个单表关联的程序,但是没有输出,只输出表头,不知道为什么(每行数据是以tab分割的),请大侠指教
public class STjoin {
public static int time = 0;
public static class Map extends Mapper<Object,Text,Text,Text>{
public void map(Object key,Text value,Context context)throws IOException,InterruptedException{
String childnName = new String();
String parentName = new String();
//String relationtype = new String();
String line = value.toString();
String[] strs= line.split(" ");
context.write(new Text(strs[1]),new Text("1"+"-"+strs[0]));//输出左表
context.write(new Text(strs[0]),new Text("2"+"-"+strs[1]));//输出右表
}
}
public static class Reduce extends Reducer<Text,Text,Text,Text>{
public void reduce(Text key,Iterable<Text> values,Context context)throws IOException,InterruptedException{
if (time == 0){//输出表头
context.write(new Text("grandchild"),new Text("grandparent"));
time++;
}
int grandchildNum = 0;
String grandchild[] = new String[20];
int grandparentNum = 0;
String grandparent[] = new String[20];
Iterator iter = values.iterator();
while (iter.hasNext()){
String record = iter.next().toString();
String[] st = record.split("-");
if(st[0].equals("1")){
grandchild[grandchildNum] =st[1];
grandchildNum ++;
} else if(st[0].equals("2")){
grandparent [grandparentNum ]=st[1];
grandparentNum ++;
}
}
//grandchild和grandparent数组求笛卡尔积
if(grandchildNum !=0 && grandparentNum !=0){
for (int m=0;m<grandchildNum;m++){
for (int n=0;n<grandparentNum;n++){
context.write(new Text(grandchild[m]),new Text(grandparent[n]));
}
}
}
}
}
public static void main(String[] args)throws Exception{
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf,args).getRemainingArgs();
if(otherArgs.length !=2){
System.err.println("Usage:...");
System.exit(2);
}
Job job = new Job(conf,"single table join");
job.setJarByClass(STjoin.class);
job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job,new Path(otherArgs[0]));
FileOutputFormat.setOutputPath(job,new Path(otherArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : -1);
}
}
...全文
相关推荐
Hadoop案例之单表关联输出祖孙关系.zip_Hadoop案例_hadoop_hadoop查询祖孙
本项目基于Hadoop MapReduce框架,通过单表自连接技术从父子关系数据中推导出祖孙关系。Map阶段以父节点为键、子节点为值进行映射,Reduce阶段对相同键的后代进行笛卡尔积计算,从而生成完
在MapReduce上的大型数据集中检测关联
在MapReduce框架上检测大型数据集中的关联,是数据科学和大数据分析领域中的一个挑战性问题。
hadoop mapreduce多表关联join多个job相互依赖传递参数
在Hadoop MapReduce环境中,处理大数据时经常遇到多表关联(Join)的需求,尤其是在复杂的业务逻辑中。
MapReduce框架下基于正负关联规则的视频人物关系挖掘
“MapReduce框架下基于正负关联规则的视频人物关系挖掘”,该研究旨在解决视频人物关系挖掘中的关系单一问题,采用MapReduce框架和正负关联规则进行人物关系的细化挖掘,对于视频内容分析具有重要
基于MapReduce的Apriori算法代码
基于MapReduce的Apriori算法代码基于MapReduce的Apriori算法代码是一个使用Hadoop MapReduce框架实现的关联规则挖掘算法,称为Apriori算法。


