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

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

问题描述

样本数据

DATE      WindDirection

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

下面的问题

每一天都是独一无二的,风向也不是唯一的,所以现在我们正在尝试获取最常见风向的 COUNT

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.

推荐答案

您必须按风向分组并获得计数.按降序排列计数并获得最上面的行.

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;

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

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