How to sort an array and return the index in hive?
问题 In hive, I wish to sort an array from largest to smallest, and get the index array. For example, the table is like this: id | value_array 1 | {30, 40, 10, 20} 2 | {10, 30, 40, 20} I with to get this: id | value_array 1 | {1, 0, 3, 2} 2 | {2, 1, 3, 0} The arries in result are the index of the initial elements. How can I achieve this? 回答1: Explode array using posexplode to get index and value, sort by value, collect array of index: select id, collect_list(pos) as result_array from ( select s.id