猪-获得最大数量 [英] Pig - Get Max Count

查看:91
本文介绍了猪-获得最大数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样本数据

DATE      WindDirection

1/1/2000  SW
1/2/2000  SW
1/3/2000  SW
1/4/2000  NW
1/5/2000  NW

以下问题

每天都是不稳定的,风向也不是唯一的,所以现在我们试图获取最常见的风向的计数

Every day is unqiue, and wind direction is not unique, SO now we are trying to get the COUNT of the most COMMON wind direction

我的查询是

weather_data = FOREACH Weather GENERATE $16 AS Date, $9 AS w_direction;
e = FOREACH weather_data 
            {
                unique_winds = DISTINCT weather_data.w_direction;
                GENERATE unique_winds, COUNT(unique_winds);
            }
dump e;

逻辑是找到DISTINCT WindDirections(大约有7个),然后按WindDirection分组并应用计数.

The logic is to find the DISTINCT WindDirections (there are like 7), then group by WindDirection and apply count.

现在我想获得风的总数或数量.

Right now I think get the total number or count of directions of winds.

推荐答案

您将不得不按风向分组并获得计数.按desc顺序对计数进行排序并获得最上面的行.

You will have to GROUP BY wind direction and get the counts.Order the counts by desc order and get the top most row.

wd = FOREACH Weather GENERATE $9 AS w_direction;
gwd = GROUP wd BY w_direction;
cwd = FOREACH gwd GENERATE group as wd,COUNT(wd.$0);
owd = ORDER cwd BY $1 DESC;
mwd  = LIMIT owd 1;
DUMP mwd;

这篇关于猪-获得最大数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆