title: How to parse url query string in Hive to multiple key-value pairs
body: <p>I'm trying to run a hive query that will produce a table with domain, key, value and count, grouped by the unique combination of domain/key/value.</p>
  
  <p>Example of the data:</p>
  
  <pre><code>http://www.aaa.com/path?key_a=5&amp;key_b=hello&amp;key_c=today&amp;key_d=blue
  http://www.aaa.com/path?key_a=5&amp;key_b=goodb&amp;key_c=yestr&amp;key_d=blue
  http://www.bbb.com/path?key_a=5&amp;key_b=hello&amp;key_c=today&amp;key_d=blue
  http://www.bbb.com/path?key_a=5&amp;key_b=goodb&amp;key_c=ystrd
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>aaa.com | key_a | 5 | 2
  aaa.com | key_b | hello | 1
  aaa.com | key_b | goodb | 1
  aaa.com | key_c | today | 1
  aaa.com | key_c | yestr | 1
  aaa.com | key_d | blue | 2
  bbb.com | key_a | 5 | 2
  bbb.com | key_b | hello | 1
  bbb.com | key_b | goodb | 1
  bbb.com | key_c | today | 1
  bbb.com | key_c | ystrd | 1
  bbb.com | key_d | blue | 1
  </code></pre>
  
  <p>Here's what I've been using:</p>
  
  <pre><code>"select parse_url(url,'HOST'), str_to_map(parse_url(url,'QUERY'),'&amp;','='), count(1) from url_table group by select parse_url(url,'HOST'), str_to_map(parse_url(url,'QUERY'),'&amp;','=') limit 10;"
  </code></pre>
  
  <p>Where am I going wrong?  Specifically where I think I'm messing up is: str_to_map(parse_url(url,'QUERY'),'&amp;','=') because I don't know how to break apart the query string into multiple key-value pairs and then group correctly.</p>