title: How to FLATTEN a test statement in Pig?
body: <p>Using Pig .12.</p>
  
  <p>I want to use a FOREACH with a block statement; the result, via GENERATE depends on some value. I know that i can use Flatten with a statement in it. I.e.:</p>
  
  <pre><code>grunt&gt; d = foreach j2 { 
         ord = order j1 by A::a1 desc; 
         l = limit ord 1; 
         generate flatten((IsEmpty(l)?'f':'g')); };
  </code></pre>
  
  <p>This works.</p>
  
  <p>But what i want to do:</p>
  
  <pre><code>grunt&gt; d = foreach j2 { 
    ord = order j1 by A::a1 desc; 
    l = limit ord 1; 
    generate flatten((l.$0=='2') ?'f':'g'); };
  </code></pre>
  
  <blockquote>
    <p>2014-05-07 22:28:08,750 [main] ERROR org.apache.pig.tools.grunt.Grunt
    - ERROR 1200:   mismatched input '?' <strong>expecting RIGHT_PAREN</strong></p>
  </blockquote>
  
  <p>Why does it say this?</p>
  
  <p>I tried:</p>
  
  <pre><code>grunt&gt; d = foreach j2 { 
  ord = order j1 by A::a1 desc; 
  l = limit ord 1; 
  generate flatten(((l.$0=='2') ?'f':'g')); };
  </code></pre>
  
  <blockquote>
    <p>2014-05-07 22:40:44,895 [main] ERROR
    org.apache.pig.tools.grunt.Grunt - ERROR 1039:
         (Name: Equal Type: null Uid: null)<strong>incompatible types in Equal Operator left hand side:bag :tuple(A::a1:chararray)  right hand side:chararray</strong></p>
  </blockquote>
  
  <p>And i dont know how to resolve this.</p>
  
  <p>I just want to generate my results in a test case, but first need to flatten the test condition. 
  Help ?
  thanks,
  Matt</p>