最近做一个PIG类的项目,重新看了下PIG,顺便做总结。看到COGROUP时感觉有些问题
A = load 'student' as (name:chararray, age:int, gpa:float); B = load 'student' as (name:chararray, age:int, gpa:float); dump B; (joe,18,2.5) (sam,,3.0) (bob,,3.5) X = cogroup A by age, B by age; dump X; (18,{(joe,18,2.5)},{(joe,18,2.5)}) (,{(sam,,3.0),(bob,,3.5)},{}) (,{},{(sam,,3.0),(bob,,3.5)})很难理解的是为什么age是空的会有2条数据?参考其他博客看下COGROUP的用法,发现不是这样。
编码无悔博客:http://www.codelast.com/?p=3621
后来自己造了一批数据来尝试没有空值和有空值的COGROUP.
CA: (jack,32,run) (liza,22,eat) (tom,20,mouse) CB: (jack,32,run) (jerry,10,steal) (tom,20,mouse) COGROUP: (tom,{(tom,20,mouse)},{(tom,20,mouse)}) (jack,{(jack,32,run)},{(jack,32,run)}) (liza,{(liza,22,eat)},{}) (jerry,{},{(jerry,10,steal)})
加一个有空值的字段。
CA: (jack,32,run) (liza,22,eat) (,20,mouse) CB: (jack,32,run) (jerry,10,steal) (,20,mouse) COGROUP: (jack,{(jack,32,run)},{(jack,32,run)}) (liza,{(liza,22,eat)},{}) (jerry,{},{(jerry,10,steal)}) (,{(,20,mouse)},{}) (,{},{(,20,mouse)})
分别加M和N个空值字段,数据量不会出现M*N个空值吧?不是2个就是个大坑,会放大数据量。
CA: (jack,32,run) (liza,22,eat) (,200,mouse) (,201,mouse) (,202,mouse) (,203,mouse) (,204,mouse) CB: (jack,32,run) (jerry,10,steal) (,301,mouse) (,302,mouse) (,303,mouse) (,304,mouse) (,305,mouse) (,306,mouse) (,307,mouse) COGROUP: (jack,{(jack,32,run)},{(jack,32,run)}) (liza,{(liza,22,eat)},{}) (jerry,{},{(jerry,10,steal)}) (,{(,200,mouse),(,201,mouse),(,202,mouse),(,203,mouse),(,204,mouse)},{}) (,{},{(,301,mouse),(,302,mouse),(,303,mouse),(,304,mouse),(,305,mouse),(,306,mouse),(,307,mouse)})
还好,是个坑,但是没有放大数据量。官方已经有人提交了patch:https://issues.apache.org/jira/browse/PIG-361