title: Keeping the order of records in Hive collect
body: <p>I have a <code>HIVE</code> table as follows:</p>
  
  <pre><code>select id, id_2, val from test order by id;
  
  234 974 0.5
  234 457 0.7
  234 236 0.5
  234 859 0.6
  123 859 0.7
  123 236 0.6
  123 974 0.5
  123 457 0.5
  </code></pre>
  
  <p>I'm trying to <code>collect</code> the data based on the <code>id</code> value. I need the collected data to be following the same order for each row. My expected output is as follows: (any order is fine as long it's the same for all the rows):</p>
  
  <pre><code>234 [974,457,236,859]   [0.5,0.7,0.5,0.6]
  123 [974,457,236,859]   [0.5,0.5,0.6,0.7]
  </code></pre>
  
  <p>I used the <code>collect</code> UDF from <a href="https://github.com/klout/brickhouse/blob/master/src/main/java/brickhouse/udf/collect/CollectUDAF.java" rel="nofollow">Brickhouse</a>.</p>
  
  <pre><code>select tmp.id, collect(id_2), collect(tmp.val) from
  (select id, id_2, val from test
  order by id) tmp
  group by tmp.id
  ;
  
  234 [974,457,236,859]   [0.5,0.7,0.5,0.6]
  123 [859,236,974,457]   [0.7,0.6,0.5,0.5]
  </code></pre>
  
  <p>As you can see, the order of the columns is not being kept. Is there any way to keep the ordering constant throughout the output? Any tips will be appreciated.</p>