(Hive, SQL) - 如何对列内的字符串列表进行排序?

(Hive, SQL) - How to sort a list of string inside a column?

我在 Hive (SQL) 中遇到大数据问题。

SELECT genre, COUNT(*) AS unique_count
FROM table_name
GROUP BY genre

结果如下:

genre           |   unique_count
----------------------------------
Romance,Crime,Drama,Law | 1560
Crime,Drama,Law,Romance | 895
Law,Romance,Crime,Drama | 942
Adventure,Action        | 3250
Action,Adventure        | 910

我想要的是按 genre ASC|DESC 对元素进行排序并得到类似

的结果
genre           |   unique_count
----------------------------------
Crime,Drama,Law,Romance | 3397
Action,Adventure        | 4160

我可以在 Python 中执行此操作,但我有超过 200 Million 行数据。我不知道有什么合理的方法可以移动这些数据。 那么我该如何实现呢?

select      concat_ws(',',sort_array(split(genre,','))) as genre
           ,count(*)                                    as unique_count

from        table_name

group by    concat_ws(',',sort_array(split(genre,',')))