1
Примеры данных для моей проблемы:Лучшие 3 записи в внутри группы по запросу в свинью
1 12 1234
2 12 1233
1 13 5555
1 15 4444
2 34 2222
7 89 1111
Field Description :
col1 cust_id ,col2 zip_code , col 3 transaction_id.
Using pig scripting i need to find the below question :
for each cust_id i need to find the zip code mostly used for last 3 transactions .
Approach I used so far :
1) Group records with cust_id :
(1,{(1,12,1234),(1,13,5555),(1,15,4444),(1,12,3333),(1,13,2323),(1,13,3434),(1,13,5755),(1,18,4424),(1,12,3383),(1,13,2823)})
(2,{(2,34,2222),(2,12,1233),(2,34,6666),(2,34,6666),(2,34,2422)})
(6,{(6,14,2312),(6,15,8888),(6,14,4634),(6,14,2712),(6,15,8288)})
(7,{(7,45,4244),(7,89,1111),(7,45,4544),(7,89,1121)})
2) Сортировать их и ограничить их на последних 3-х операций.
Using nested foreach i have sorted by transaction id and limit that to 3
nested = foreach group_by { sor = order zip by $2 desc ; limi = limit sor 3 ; generate limi; };
After grouping data is :
({(1,12,1234),(1,13,2323),(1,13,2823)})
({(2,12,1233),(2,34,2222),(2,34,2422)})
({(6,14,2312),(6,14,2712),(6,14,4634)})
({(7,89,1111),(7,89,1121),(7,45,4244)})
Почему мои данные не сортируются по убыванию в порядке убывания?
Даже по возрастанию, теперь как найти наиболее используемый почтовый индекс для последних 3 транзакций.
Result should be
1) 13
2) 34
3) 14
4) 89