title: hadoop pig script - union with condition
body: <p>I am entirely new to Pig. I want to union two files A and B using iid field, but I dont want the output has any iids (from B) that A doesn't have. This seems to be simple, but I cannot figure out how to do it correctly.</p>
  
  <p>Here is my sample code that has union only:</p>
  
  <pre><code>a = load '$input' as (iid:int, field:chararray, v1:chararray, v2:chararray, v3:chararray);
  b = load '$data' as (iid:int, field:chararray, v1:chararray, v2:chararray, v3:chararray);
  out = union onschema a,b;
  singled = distinct out;
  ordered = order singled by iid;
  store ordered into '$output';
  </code></pre>
  
  <p>Below is the sample data with only 3 columns to describe what I expect. Note that fields are actually tab delimited.</p>
  
  <p>Sample data A:</p>
  
  <pre><code>1  Name   Tom Linkon
  1  Title  Professor
  2  Name   Whatever
  2  Title  Worker
  </code></pre>
  
  <p>Sample data B:</p>
  
  <pre><code>1  City  New York
  2  City  Columbus
  3  City  Fake fake
  4  City  Blah Bla
  </code></pre>
  
  <p>Sample output</p>
  
  <pre><code>1  Name   Tom Linkon
  1  Title  Professor
  1  City   New York
  2  Name   Whatever
  2  Title  Worker
  2  City   Columbus
  </code></pre>
  
  <p>Thanks a lot for your help!</p>