title: Collect to ordered set in hive
body: <p>using Hive's built in collect_set, I was going to implement a query where I could reliably know that the arrays 0 index was the first element collected, and the last index was the last element collected. -Example: </p>
  
  <pre><code>cookie  page_num, 
  1234      1 
  1234      2 
  1234      3 
  1234      4 
  4444      1
  4444      2 
  </code></pre>
  
  <p>Query: </p>
  
  <pre><code>select cookie, collect_set(page_num) as page_set 
  from mytable  
  group by cookie
  </code></pre>
  
  <p>Desired Reults: </p>
  
  <pre><code>1234  [1,2,3,4] 
  4444  [1,2] 
  </code></pre>
  
  <p>Actual un-ordered result:  </p>
  
  <pre><code>1234 [2,4,1,3] 
  4444 [2,1] 
  </code></pre>
  
  <p>How can I collect to a sorted array where the sort is based on the order of incoming rows? </p>