title: Apache Pig: apply LIMIT inside foreach referencing toplevel field
body: <p>I'm having trouble referencing a "parent" field within a <code>foreach</code>:</p>
  
  <pre><code>grunt&gt; describe METRICS_SOURCE_WITH_CNT
  METRICS_SOURCE_WITH_CNT: 
  {group: (hostname: chararray,site_guid: chararray,timestamp: long),
  JOIN_FIELDS_ONLY: {(timestamp: long, unique_pageviews: long)},cnt: long
  </code></pre>
  
  <p>Note that <code>cnt</code> is total of tuples.</p>
  
  <pre><code>METRICS_SOURCE_TOP3 = foreach METRICS_SOURCE_WITH_CNT {
  
      SORTED = ORDER JOIN_FIELDS_ONLY by unique_pageviews DESC;
      TOPK = LIMIT SORTED 10;
  
      REVSORTED = ORDER JOIN_FIELDS_ONLY by unique_pageviews ASC;
      BOTTOMK = LIMIT REVSORTED cnt;
  
      generate TOPK, BOTTOMK;
  }
  </code></pre>
  
  <p>But it seems that when I'm applying the second <code>LIMIT</code>, Pig thinks that the <code>cnt</code> field is within <code>REVSORTED</code>, but it is actually a "parent" field.</p>
  
  <pre><code>Invalid field projection. Projected field [cnt] does not exist in schema: timestamp:long,....
  </code></pre>
  
  <p>I've tried referencing fields by number <code>$x</code> but it doesn't work. Pig always thinks that the referenced field is within the relation being <code>LIMIT</code>'d</p>