Is Hive's collect_list ordered?

2019-04-11 21:00发布

This page says of collect_list:

Returns a list of objects with duplicates.

Is that list ordered? For example, the order of the query results?

标签: hive hiveql
2条回答
混吃等死
2楼-- · 2019-04-11 21:47

built-in collect_list isn't guaranteed to be ordered, even if you do an order by first (even if it did ensure order, doing it this way is a waste of time). Just use brickhouse collect; it ensures the elements are ordered.

查看更多
虎瘦雄心在
3楼-- · 2019-04-11 21:56

It's correct that collect_list isn't guaranteed to be ordered. The function sort_array will sort the result:

   select a, b, sort_array(collect_list(c)) as sorted_c
   from the_table
   group by a, b
查看更多
登录 后发表回答