title: Can I generate nested bags using nested FOREACH statements in Pig Latin?
body: <p>Let's say I have a data set of restaurant reviews:</p>
  
  <pre><code>User,City,Restaurant,Rating
  Jim,New York,Mecurials,3
  Jim,New York,Whapme,4.5
  Jim,London,Pint Size,2
  Lisa,London,Pint Size,4
  Lisa,London,Rabbit Whole,3.5
  </code></pre>
  
  <p>And I want to produce a list by user and city of average review. I.e. output:</p>
  
  <pre><code>User,City,AverageRating
  Jim,New York,3.75
  Jim,London,2
  Lisa,London,3.75
  </code></pre>
  
  <p>I could write a Pig script as follows:</p>
  
  <pre><code>Data = LOAD 'data.txt' USING PigStorage(',') AS (
      user:chararray, city:chararray, restaurant:charray, rating:float
  );
  
  PerUserCity = GROUP Data BY (user, city);
  
  ResultSet = FOREACH PerUserCity {
      GENERATE group.user, group.city, AVG(Data.rating);
  }
  </code></pre>
  
  <p>However I'm curious whether I can first group the higher level group (the users) and then sub group the next level (the cities) later: i.e.</p>
  
  <pre><code>PerUser = GROUP Data BY user;
  
  Intermediate = FOREACH PerUser {
      B = GROUP Data BY city;
      GENERATE group AS user, B;
  }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Error during parsing.
  Invalid alias: GROUP in {
    group: chararray,
    Data: {
      user: chararray,
      city: chararray,
      restaurant: chararray,
      rating: float
    }
  }
  </code></pre>
  
  <p>Has anyone tried this with success? Is it simply not possible to GROUP within a FOREACH?</p>
  
  <p>My goal is to do something like:</p>
  
  <pre><code>ResultSet = FOREACH PerUser {
      FOREACH City {
          GENERATE user, city, AVG(City.rating)
      }
  }
  </code></pre>