首页 > 其他 > 详细

pig小例1

时间:2015-04-23 21:30:01      阅读:294      评论:0      收藏:0      [点我收藏+]

前提:假如有一批输入数据格式如下:

用户id|文章类别|浏览次数

技术分享

 

 

 

 

 

 

要求:用pig求出每个用户浏览次数最多的文章类别?

1.首先:读入数据

– 指定分隔符为 “|”
– 指定每个字段的类型

进入pig,  u_ct=load‘/output‘ using PigStorage(‘|‘) as(user:chararray,category:chararray,times:int);

2.分用户统计:
– group:对相同user的记彔进行聚合
– sorted: 根据times从大到小进行排序
– top: 保留sorted的第一行

u_stat=foreach (group u_ct by user){sorted= order u_ct by times desc; top= limit sorted 1; generate flatten(top),SUM(u_ct.times)};

3.输出: store u_stat into ‘/stat‘;

4 展示:cat /stat

技术分享

pig小例1

原文:http://www.cnblogs.com/mlj5288/p/4451467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!