title: How does 'group as' work in Pig?
body: <p>I'm having trouble understanding how <code>group by group_name</code> works in a <code>foreach</code> loop.</p>
  
  <p>Let's say we already have a variable named <code>grouped_data</code> that was defined as:</p>
  
  <pre><code>grouped_data = group dataset by (emp_id, dept_id);
  </code></pre>
  
  <p>And then we want to iterate over each record in <code>grouped_data</code> with an aggregated column added in. So the following is written: </p>
  
  <pre><code>with_hours_worked = FOREACH grouped_data 
                      GENERATE group AS grp, 
                               SUM(dataset.worked_hours) AS hours ;
  </code></pre>
  
  <p>I'm confused as to what is going on in that last line, especially the <code>group AS grp</code> part. Is <code>grp</code> a tuple? Is the line from <code>grouped_data</code> converted back into a group? If so, why?</p>