Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Pig Wiki" for change 
notification.

The following page has been changed by AmirYoussefi:
http://wiki.apache.org/pig/PigLatin

------------------------------------------------------------------------------
  $ 
  }}}
  
+ 
+ [[Anchor(OUTER JOIN)]]
+ ===== Outer Join =====
+ 
+ Outer join by example:
+ 
+ {{{
+ A = load 'test1';
+ grunt> dump A;
+ (k1, vq)
+ (k1, v2)
+ (k2, v3)
+ (k2, v4)
+ (k3, v5)
+ (k4, v6)
+ 
+ B = load 'test2';
+ grunt> dump B;
+ (k1, w1)
+ (k2, w2)
+ (k2, w3)
+ (k3, w4)
+ (k8, w8)
+ 
+ CG = COGROUP A by $0, B by $0;
+ grunt> dump CG;
+ (k1, {(k1, vq), (k1, v2)}, {(k1, w1)})
+ (k2, {(k2, v3), (k2, v4)}, {(k2, w2), (k2, w3)})
+ (k3, {(k3, v5)}, {(k3, w4)})
+ (k4, {(k4, v6)}, {})
+ (k8, {}, {(k8, w8)})
+ 
+ A_ONLY_FILTERED =  FILTER CG by (COUNT(B) == '0');
+ A_ONLY_FLAT = FOREACH A_ONLY_FILTERED GENERATE FLATTEN(A);
+ dump A_ONLY_FLAT;
+ 
+ (k4, v6)
+ 
+ 
+ B_ONLY_FILTERED =  FILTER CG by (COUNT(A) == '0');
+ B_ONLY_FLAT = FOREACH B_ONLY_FILTERED GENERATE FLATTEN(B);
+ dump B_ONLY_FLAT;
+ 
+ (k8, w8)
+ 
+ B_AND_A_FILTERED =  FILTER CG by ((COUNT(A) != '0') and (COUNT(B) != '0'));
+ B_AND_A_FLAT = FOREACH B_AND_A_FILTERED GENERATE FLATTEN(B);
+ dump B_AND_A_FLAT;
+ 
+ (k1, w1)
+ (k2, w2)
+ (k2, w3)
+ (k3, w4)
+ 
+ }}}
+ 
+ Another way is following: 
+ 
+ {{{
+ A = load 'test1';
+ B = load 'test2';
+ CG_I_O = COGROUP A by $0 inner, B by $0 outer;
+ F = FOREACH CG_I_O GENERATE A, ((COUNT(B) == '0')? '' : B) as MODIFIED_B;
+ G = FOREACH F GENERATE FLATTEN(A), FLATTEN(MODIFIED_B);
+ -- You can do it in one pass: Y = FOREACH CG_I_O GENERATE FLATTEN(A), 
FLATTEN(((COUNT(B) == '0')? '' : B));
+ dump G;
+ 
+ (k1, vq, k1, w1)
+ (k1, v2, k1, w1)
+ (k2, v3, k2, w2)
+ (k2, v4, k2, w2)
+ (k2, v3, k2, w3)
+ (k2, v4, k2, w3)
+ (k3, v5, k3, w4)
+ (k4, v6, )
+ }}}
+ 
  [[Anchor(Embedded_Pig_Latin)]]
  === Embedded Pig Latin ===
  

Reply via email to