title: Converting single tuple with multiple bags into multiple tuples in Pig
body: <p>I have a line like the following:</p>
  
  <pre><code>evnt=redeem&amp;lid=1030023&amp;upt=1679&amp;pid=000000000001076056,000000000001072654,000000000001067925&amp;ppt=996,246,366&amp;qty=1,2,3
  </code></pre>
  
  <p>I am interested in extracting the lid, pid, ppt, and qty out of the line and creating a tuple for every entry in the pid, ppt and qty. Notice that the rules are:</p>
  
  <ul>
  <li>Everything except the lid can have multiple values. When there are commas in the value, there are multiple values</li>
  <li>The pid can have multiple values and these values are correlated with the same order as the other values. For example, <code>lid=4&amp;pid=1,2&amp;qty=2,3&amp;ppt=123,232</code> means if <code>lid=4</code> and <code>pid=1</code> then <code>qty=2</code> and <code>ppt=123</code>, and if <code>lid=4</code> and <code>pid=2</code> then <code>qty=3</code> and <code>ppt=232</code>.</li>
  <li>ppt follows the same rule as qty in that it correlates to the pid. </li>
  </ul>
  
  <p>I've been able to accomplish this for the lid and the pid of those fields with the following:</p>
  
  <pre><code>logs = foreach logs generate
                      REGEX_EXTRACT(original_path, 'lid=([^&amp;]+)', 1) as login_id,
                      FLATTEN(TOKENIZE(REPLACE(REGEX_EXTRACT(original_path, '.*pid=([^&amp;]+)', 1), ',', ' '))) as pid;
  </code></pre>
  
  <p>This gives me:</p>
  
  <pre><code>1030023    000000000001076056
  1030023    000000000001072654
  1030023    000000000001067925
  </code></pre>
  
  <p>However, I want to do this for the other two fields as well (leaving it at three tuples) and multiple flattens in the same foreach statement isn't going to give me what I want.</p>
  
  <pre><code>1030023    000000000001076056    996    1
  1030023    000000000001072654    246    2
  1030023    000000000001067925    366    3
  </code></pre>
  
  <p>I am guessing this is going to require a UDF, but I'd like to know if there's another way around it by using only the provided functions in Pig.</p>