title: how to use Posexplode function in hive
body: <p>I am using <code>posexplode</code> to split single to multiple records in hive. 
  Along with multiple records as output i need to generate sequence number for each row.</p>
  
  <p><code>col1</code>, <code>col2</code>, <code>col3</code> and <code>col4</code> are defined as string because rarely we get alpha data as well.</p>
  
  <pre><code>col1 | col2| col3 | col4 
  ---------------------------
    7  |  9  |  A   |  3
    5  |  6  |  9
  
  Seq | Col
  ----------
   1  |  7
   2  |  9
   3  |  A
   4  |  3
   1  |  5
   2  |  6
   3  |  9
  </code></pre>
  
  <p>I am using below mentioned query but I am getting error </p>
  
  <blockquote>
    <p><code>-bash: syntax error near unexpected token (</code></p>
  </blockquote>
  
  <p>My query is :</p>
  
  <pre><code>SELECT  
      seq, col  
  FROM 
    (SELECT  array(  col1, col2 , col3,col4) as arr_r FROM srctable ) arrayrec
  LATERAL VIEW posexplode(arrayrec) EXPLODED_rec as seq, col 
  </code></pre>
  
  <p>How can this be resolved</p>
  
  <p>I am able to run successfully this query :</p>
  
  <pre><code>SELECT  col  FROM 
  (SELECT  array(  col1, col2 , col3,col4) 
  as arr_r FROM srctable ) arrayrec
  LATERAL VIEW explode(arrayrec) EXPLODED_rec as col
  </code></pre>
  
  <p>Which produces below output</p>
  
  <pre><code>  Col
   -----
     7
     9
     A
     3
     5
     6
     9
  </code></pre>
  
  <p>I have checked the link : <a href="https://stackoverflow.com/questions/25355916/how-to-get-first-n-elements-in-an-array-in-hive/25416301#25416301">How to get first n elements in an array in Hive</a></p>