做mapreduce join时遇到的问题
来源:互联网 发布:js div的显示与隐藏 编辑:程序博客网 时间:2024/05/17 18:47
遇到的问题:
1、有关text的问题(还是没想明白)
@Override
protectedvoid reduce(TextPair key, Iterable<Text> values, Contextcontext)
throwsIOException, InterruptedException {
//TODO Auto-generated method stub
Textt1 =new Text();
Textk1 = key.getKey1();
System.out.println("k1:" + k1);
Iterator<Text>it = values.iterator();
t1= it.next();
while(it.hasNext()) {
Textt2 = it.next();
//这里有个奇怪的问题:newText(t2.toString() + "\t" +t1.toString())的值是2个t2的值,而不是t1和t2的值
context.write(k1,new Text(t2.toString() + "\t" + t1.toString()));
}
}
修改为如下:
@Override
protectedvoid reduce(TextPair key, Iterable<Text> values, Contextcontext)
throwsIOException, InterruptedException {
//TODO Auto-generated method stub
Stringt1 =null;
Textk1 = key.getKey1();
Iterator<Text>it = values.iterator();
t1= it.next().toString();
while(it.hasNext()) {
Stringt2 = it.next().toString();
context.write(k1,new Text(t2 + "\t" + t1));
}
}
2、job.setGroupingComparatorClass(MyGroupingComparator.class);
这个函数的作用是指定哪些key放到同一个iterator里面,并且输出值中的key就是第一个key,所以其他的key就不存在了,默认情况下,它只会将key完全相同的放到一起,而不是按照partitioner的结果来存放到同一个iterator中,partitioner的结果是按照要求将map的输出到同一个reduce中,并没有产生iterator。所以,在本例中,如果不设置GroupingComparator,输出结果就为:
1003 201004 jkl 201001 abc
1005 201006 pqr 201002 def
如果按照key1设置grouping,就是将key1相同的放到同一个iterator中,就可以得到正确的结果:
1003 201001 abc kaka
1003 201004 jkl kaka
1004 201005 mno da
1005 201002 def jue
1005 201006 pqr jue
1006 201003 ghi zhao
3、test问题
importorg.apache.hadoop.io.LongWritable;
importorg.apache.hadoop.io.Text;
importorg.apache.hadoop.mrunit.mapreduce.MapDriver;
importorg.junit.Test;
publicclassMyMapperTest {
@Test
publicvoidprocessesValidRecord()throwsException {
Textvalue =newText();
value.set("201001 1003 abc");
TextPairtextPair =newTextPair();
textPair.setKey1(newText("1003"));
textPair.setKey2(newText("1"));
TextoutValue =newText("201001"+"\t"+"abc");
newMapDriver<LongWritable, Text, TextPair, Text>()
.withMapper(newMyMapper())
.withInput(newLongWritable(0), value)
.withOutput(textPair,outValue).runTest();
}
}
这个是对MyMapper中有关data.info部分的测试,这里刚开始的时候,在写TextPair类的时候,并没有覆写
@Override
publicinthashCode() {
//TODOAuto-generated method stub
returnInteger.parseInt(this.getKey1().toString())* 157
+Integer.parseInt(this.getKey2().toString());
}
@Override
publicbooleanequals(Object obj) {
//TODOAuto-generated method stub
TextPairo = (TextPair) obj;
returnthis.getKey1().equals(o.key1)&&this.getKey2().equals(o.key2);
}
@Override
publicString toString() {
//TODOAuto-generated method stub
returnthis.getKey1().toString()+"\t"+this.getKey2().toString();
}
上面这3个方法,导致怎么测试都不能成功,即使结果完全一样也没有通过测试,后来,覆写之后就成功了。
- 做mapreduce join时遇到的问题
- MapReduce编程遇到的问题
- 记录mapreduce遇到的问题
- MapReduce实现用户画像时遇到的一些问题
- 做MDB时遇到的一个问题
- 做中国象棋时遇到的问题
- 做douban客户端时遇到的问题
- 做学生系统时遇到的问题
- 做程序时遇到的问题
- 做个人网站时遇到的问题
- 做图形统计时遇到的问题
- SSM做项目时遇到的问题
- MapReduce的Join
- mysql left join实际遇到的问题
- 第一个MapReduce程序遇到的问题
- MapReduce运行中遇到的问题
- hadoop MapReduce初试遇到的问题
- 使用MapReduce求解join问题
- window7 64位系统下如何使用 PLSQL DEVELOPER 8
- uCGUI 驱动LCD提速 STM32F主芯
- 一个学习PCI Express的 不错去处
- Storm 单机环境的安装与配置
- source insight 2
- 做mapreduce join时遇到的问题
- input只能输入数字和小数点
- 笔试题四:带头节点head两个链表合并,并且有序
- perl入门
- enctype已经设置为multipart/form-data 但request.getinputstream()仍然为null
- 【总结】Python 2.x中常见字符编码和解码方面的错误及其解决办法
- poj1067(威佐夫博弈)
- 从支付宝获取的跳转提示
- 笔试题五:实现输出矩阵 二维数组