title: Hadoop: Create empty bag if field is null in Pig
body: <p>I have an example of the following data</p>
  
  <pre><code>id : long,
  list: {(itemId: Long, itemName: charArray)}
  </code></pre>
  
  <p>In my data, list can either be a bag of tuples or null. I would like to change the null into an empty bag (consisting of 0 elements)</p>
  
  <p>I tried something like :</p>
  
  <pre><code>answer = FOREACH data
   GENERATE (list is null ? {} : list) AS list;
  </code></pre>
  
  <p>It says that {} and list are not compatible schemas. I am wondering how I can create an empty bag with a compatible schema</p>
  
  <p>I ended up doing this and it worked:</p>
  
  <pre><code>answer = FOREACH data
  GENERATE (list is null ? (bag{tuple(long,chararray)}){} : list) AS list:{(itemId: long, itemName: charArray)};
  </code></pre>