--Read Data
data = LOAD '/user/mapred/pigdata.txt ' USING pigstorage (' | ') As (Imsi:chararray,time:chararray,loc:chararray);
--Conversion format
Register/home/mapred/software/hadoops/pig/pig-0.11.1/contrib/piggybank/java/piggybank.jar;
Register/home/mapred/practise/joda-time-2.0.jar;
Total_count = FOREACH (group flt by Loc) GENERATE GROUP as Loc,count (FLT) as total;
--Calculate the number of positions per pair
Pairs_count = FOREACH (group flt by (Loc,next_loc)) GENERATE Flatten (group) as (Loc,next_loc), COUNT (FLT) as CNT;
Jnd = JOIN Pairs_count by Loc,total_count by Loc USING ' replicated ';
Prob = FOREACH jnd GENERATE pairs_count::loc as Loc, Pairs_count::next_loc as Next_loc, (double) cnt/(double) total as Probab ility;
TOP3 = FOREACH (GROUP prob by Loc)
{
sorted = order prob by probability DESC;
top = LIMIT sorted 3;
GENERATE flatten (top);
};
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.