title: How to perform a DISTINCT in Pig Latin on a subset of columns?
body: <p>I would like to perform a DISTINCT operation on a subset of the columns.  The <a href="http://pig.apache.org/docs/r0.11.1/basic.html#distinct">documentation</a> says this is possible with a nested foreach:</p>
  
  <blockquote>
    <p>You cannot use DISTINCT on a subset of fields; to do this, use FOREACH and a nested block to first select the fields and then apply DISTINCT (see Example: Nested Block).</p>
  </blockquote>
  
  <p>It is simple to perform a DISTINCT operation on all of the columns:</p>
  
  <pre><code>A = LOAD 'data' AS (a1,a2,a3,a4);
  A_unique = DISTINCT A;
  </code></pre>
  
  <p>Lets say that I am interested in performing the distinct across a1, a2, and a3. Can anyone provide an example showing how to perform this operation with a nested foreach as suggested in the documentation?</p>
  
  <p>Here's an example of input and expected output:</p>
  
  <pre><code>A = LOAD 'data' AS(a1,a2,a3,a4);
  DUMP A;
  
  (1 2 3 4)
  (1 2 3 4)
  (1 2 3 5)
  (1 2 4 4)
  
  -- insert DISTINCT operation on a1,a2,a3 here:
  -- ...
  
  DUMP A_unique;
  
  (1 2 3 4)
  (1 2 4 4)
  </code></pre>