我有一个表,其中的行具有以下格式
user | purchase | time_of_purchase|quantity
样品
1234 | Bread | Jul 7 20:48| 1
1234 | Shaving Cream | July 10 14:20 | 2
5678 | Milk | July 7 3:48 | 1
5678 | Bread | July 7 3:49 | 2
5678 | Bread | July 7 15:30 | 1
我想以以下格式创建用户的购买历史记录
1234 | {[Bread , Jul 7 20:48,1] ,[ Shaving Cream , July 10 14:20, 2 ]}
5678 | {[Milk, July 7 3:48 , 1 ] , [Bread , July 7 3:49 , 2], [Bread , July 7 15:30 , 1]}
是否可以在 hive 或 pig 脚本中执行此操作?我尝试了collect_list,但是没有保持跨列的顺序进行合并,还尝试了Brickhouse collect,但是其行为类似于collect_set,我丢失了部分信息。
最佳答案
PIG脚本
File = LOAD 'file.txt' using PigStorage(',') as (user:int, Purchase:chararray, timeofpurchase:chararray, quantity:int);
GRP_USER = GROUP File by user;
DUMP GRP_USER;
你可以在http://ybhavesh.blogspot.com/上举几个例子
希望它对有帮助