title: Using FILTER after FOREACH in Pig-Latin failed
body: <p>I am a beginner in Pig-Latin and I found a problem about FILTER statement. Look at the example:</p>
  
  <p>Suppose we have a data file(test.txt) whose content is:</p>
  
  <pre><code>1,2,3
  2,3,4
  3,4,5
  4,5,6
  </code></pre>
  
  <p>I want to select the records whose the 1st field is '3'. The Pig script is:</p>
  
  <pre><code>t = LOAD 'test.txt' USING PigStorage(',');
  t1 = FOREACH t GENERATE $0 AS i0:chararray, $1 AS i1:chararray, $2 AS i2:chararray;
  f1 = FILTER t1 BY i0 == '3';
  DUMP f1
  </code></pre>
  
  <p>The task runs well but the output result is nothing. EXPLAIN f1 shows:</p>
  
  <pre><code>#--------------------------------------------------
  # Map Reduce Plan                                  
  #--------------------------------------------------
  MapReduce node scope-27
  Map Plan
  f1: Store(fakefile:org.apache.pig.builtin.PigStorage) - scope-26
  |
  |---f1: Filter[bag] - scope-22
      |   |
      |   Equal To[boolean] - scope-25
      |   |
      |   |---Project[chararray][0] - scope-23
      |   |
      |   |---Constant(3) - scope-24
      |
      |---t1: New For Each(false,false,false)[bag] - scope-21
          |   |
          |   Project[bytearray][0] - scope-15
          |   |
          |   Project[bytearray][1] - scope-17
          |   |
          |   Project[bytearray][2] - scope-19
          |
          |---t: Load(file:///Users/woody/test.txt:PigStorage(',')) - scope-14--------
  Global sort: false
  ----------------
  </code></pre>
  
  <p>However, if I change the head 2 lines into:</p>
  
  <pre><code>t1 = LOAD 'test.txt' USING PigStorage(',') AS (i0:chararray, i1:chararray, i2:chararray)
  </code></pre>
  
  <p>(i.e. assign the schema in LOAD statement)</p>
  
  <p>The task works well and the result is also correct. In this case, the EXPLAIN f1 shows:</p>
  
  <pre><code>#--------------------------------------------------
  # Map Reduce Plan                                  
  #--------------------------------------------------
  MapReduce node scope-33
  Map Plan
  f1: Store(fakefile:org.apache.pig.builtin.PigStorage) - scope-32
  |
  |---f1: Filter[bag] - scope-28
      |   |
      |   Equal To[boolean] - scope-31
      |   |
      |   |---Project[chararray][0] - scope-29
      |   |
      |   |---Constant(3) - scope-30
      |
      |---t1: New For Each(false,false,false)[bag] - scope-27
          |   |
          |   Cast[chararray] - scope-19
          |   |
          |   |---Project[bytearray][0] - scope-18
          |   |
          |   Cast[chararray] - scope-22
          |   |
          |   |---Project[bytearray][1] - scope-21
          |   |
          |   Cast[chararray] - scope-25
          |   |
          |   |---Project[bytearray][2] - scope-24
          |
          |---t1: Load(file:///Users/woody/test.txt:PigStorage(',')) - scope-17--------
  Global sort: false
  ----------------
  </code></pre>
  
  <p>Is it a Pig's bug? or is there any good way to avoid it ?</p>
  
  <p>pig --version on my computer is:</p>
  
  <pre><code>Apache Pig version 0.9.2 (r1232772)
  compiled Jan 18 2012, 07:57:19
  </code></pre>