title: How to Find the Distinct Values in a DataBag?
body: <p>Say I have some data like</p>
  
  <pre><code>1,A
  1,A
  1,B
  2,C
  2,D
  3,E
  3,E
  </code></pre>
  
  <p>I want to be able to group the first column and then return the distinct values in that group:</p>
  
  <pre><code>1,A,B
  2,C,D
  3,E
  </code></pre>
  
  <p>or </p>
  
  <pre><code>1,{A,B}
  2,{C,D}
  3,{E}
  </code></pre>
  
  <p>Is there a way to do this aside from a UDF?</p>
  
  <p>If I do</p>
  
  <pre><code>DATA = LOAD 'data.txt' USING PigStorage(',') AS (a:int, b:chararray);
  
  GROUPED = GROUP DATA BY a;
  
  UNIQUES = FOREACH GROUPED {
      distinct_bs = DISTINCT GROUPED.b;
      GENERATE
          group AS a
          ,FLATTEN(distinct_bs)
      ;
  }
  </code></pre>
  
  <p>(regardless of FLATTEN or not, or if I include the <code>group as a</code>, I receive a </p>
  
  <pre><code>ERROR 1200: org.apache.pig.newplan.logical.expression.ScalarExpression
  cannot be cast to org.apache.pig.newplan.logical.expression.ProjectExpression
  </code></pre>