title: Sorting within collect_list() in hive
body: <p>Let's say I have a hive table that looks like this:</p>
  
  <pre><code>ID    event    order_num
  ------------------------
  A      red         2
  A      blue        1
  A      yellow      3
  B      yellow      2
  B      green       1
  ...
  </code></pre>
  
  <p>I'm trying to use collect_list to generate a list of events for each ID. So something like the following:</p>
  
  <pre><code>SELECT ID, 
  collect_list(event) as events_list,
  FROM table
  GROUP BY ID;
  </code></pre>
  
  <p>However, within each of the IDs that I group by, I need to sort by order_num. So that my resulting table would look like this:</p>
  
  <pre><code>ID    events_list
  ------------------------
  A      ["blue","red","yellow"]
  B      ["green","red"]
  </code></pre>
  
  <p>I can't do a global sort by ID and order_num before the collect_list() query because the table is massive. Is there a way to sort by order_num within collect_list?</p>
  
  <p>Thanks!</p>