sort_array order by a different column, Hive sort_array order by a different column, Hive hadoop hadoop

sort_array order by a different column, Hive


It is possible to do it using only built-in functions, but it is not a pretty site :-)

select      clientid           ,split(regexp_replace(concat_ws(',',sort_array(collect_list(concat_ws(':',cast(date as string),product)))),'[^:]*:([^,]*(,|$))','$1'),',') as prod_list           ,sort_array(collect_list(date)) as date_orderfrom        tablename group by    clientid; 

+----------+-----------------------------------+------------------------------------------+| clientid |             prod_list             |                date_order                |+----------+-----------------------------------+------------------------------------------+|      100 | ["Conditioner","Shampoo","Cream"] | ["2015-12-31","2016-01-02","2016-02-12"] ||      101 | ["Book2","Book","Bookmark"]       | ["2016-01-03","2016-02-04","2016-07-10"] |+----------+-----------------------------------+------------------------------------------+