如何根据另一个 table 中的排名对一个 table 中的列进行排序
How to sort a column in one table based on the rank in another table
我有一个 table Table 1,其中有 User_ID 和 Item_List,其中项目随机排列
Customer_id Item_List
22 1,4,3,2
24 6,3,2,1
23 4,5,7,8
Table 2 有物品按照最高价值排名
Item_Id Item_Rank
1 8
2 5
3 3
4 4
5 2
6 7
7 1
8 6
我想制作一个 Table 具有 Customer_id 的相应项目列表,根据 Table 中的项目排名 2
Customer_id Ranked_Item_List
22 3,4,2,1
24 3,2,6,1
23 7,5,4,8
我不知道在 hive 中有什么有效的方法可以做到这一点。有什么建议吗?
我可以用两种不同的方式思考,创建你的 UDF 以避免爆炸或
select customer_id, collect_list(item_id) from (
select customer_id, item_id, item_rank from
table1 lateral view inline(item_list) item_id join
table2 on table1.item_id = table2.item_id --this should be done as mapjoin if your rank table is not big
) distributed by customer_id, sort by item_rank;
就像我之前说的,根据您的数据大小,您可以创建一个 UDF 以根据您的查找在映射器级别应用排序 table
我有一个 table Table 1,其中有 User_ID 和 Item_List,其中项目随机排列
Customer_id Item_List
22 1,4,3,2
24 6,3,2,1
23 4,5,7,8
Table 2 有物品按照最高价值排名
Item_Id Item_Rank
1 8
2 5
3 3
4 4
5 2
6 7
7 1
8 6
我想制作一个 Table 具有 Customer_id 的相应项目列表,根据 Table 中的项目排名 2
Customer_id Ranked_Item_List
22 3,4,2,1
24 3,2,6,1
23 7,5,4,8
我不知道在 hive 中有什么有效的方法可以做到这一点。有什么建议吗?
我可以用两种不同的方式思考,创建你的 UDF 以避免爆炸或
select customer_id, collect_list(item_id) from (
select customer_id, item_id, item_rank from
table1 lateral view inline(item_list) item_id join
table2 on table1.item_id = table2.item_id --this should be done as mapjoin if your rank table is not big
) distributed by customer_id, sort by item_rank;
就像我之前说的,根据您的数据大小,您可以创建一个 UDF 以根据您的查找在映射器级别应用排序 table