title: Hive Lateral View Explode
body: <p>I have data that has a nested mapping in one of the fields. For example, the data is in a table called 'customers' and looks like this:</p>
  
  <p>Name: Bill Jones</p>
  
  <p>Address: {"billing":{"street":"123 Main", "city":"Chicago", "state":"IL"},"shipping":{"street":"432 Copper", "city":"New York", "state":"NY"}}</p>
  
  <p>What sort of query can I write to explode the entire dataset out?</p>
  
  <p>I started with the following:</p>
  
  <pre><code>select name, key1, value1
  from customers
  lateral view explode(address) table1 as key1, value1
  </code></pre>
  
  <p>That got me part of the way there. It splits up the "billing" and "shipping" fields. However, I can't explode out the remaining. I tried this, but got an error message:</p>
  
  <pre><code>select name, key1, key2, value2
  from customers
  lateral view explode(address) table1 as key1, value1
  lateral view explode(value1) table2 as key2, value2
  </code></pre>
  
  <p>I know I'm not doing it right, but not sure what the fix is?</p>
  
  <p>Thanks,</p>
  
  <p>Chetan</p>