title: How to use CASE statement in pig?
body: <p>I need the following output.</p>
  
  <pre><code>NE 50
  SE 80
  </code></pre>
  
  <p>I am using pig query to count the country based on zone.</p>
  
  <pre><code>c1 = group country by zone;
  c2 = foreach c1 generate COUNT(country.zone), (
  case country.zone
  when 1 then 'NE'
  else 'SE'
  );
  </code></pre>
  
  <p>But I am not able to achieve my output. I am getting error like the following:</p>
  
  <pre><code>2016-03-30 13:57:16,569 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1039: (Name: Equal Type: null Uid: null)incompatible types in Equal Operator left hand side:bag :tuple(zone:int)  right hand side:int
  Details at logfile: /home/cloudera/pig_1459370643493.log
  </code></pre>
  
  <p>But I was able to do using following query.</p>
  
  <pre><code>c2 = foreach c1 generate group, COUNT(country.zone);
  </code></pre>
  
  <p>This will give following output:</p>
  
  <pre><code>(1,50)
  (2,80)
  </code></pre>
  
  <p>How can I add NE instead of 1 and SE instead of 2? I thought using CASE would help but I am getting error. Can anyone help?</p>