阿帕奇猪试图获得最大计数各组 [英] apache Pig trying to get max count in each group

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

问题描述

我在猪格式的数据。

{(组的productId,计数)}

现在我想要得到最大计数各组中,输出可能如下所示

Now I want to get maximum count in each group and the output might look as follows

{(组的productId,MAXCOUNT)} 。下面是示例输入数据

{(group, productId, maxCount)}. Here is the sample input data


  • (南美洲,PROD1,45),(南美,Prod2的,36),(拉丁美洲,PROD1,48),(拉丁美洲,prod5,35)

  • (south America,prod1, 45),(south America,prod2, 36), (latin america, prod1, 48),(latin america, prod5,35)

以下是此输入输出看起来像

here is the output for this input look like


  1. (南美,PROD1,45)

  2. (北美,Prod2的,36)

  3. (拉丁美洲,PROD1,48)

  1. (south america, prod1, 45)
  2. (North America, prod2, 36)
  3. (latin america, prod1, 48)

有人可以帮助我在此。

推荐答案

根据您的样本输入数据,这应该做的伎俩:

Based on your sample input data, this should do the trick:

data = load 'sf.csv' using PigStorage(',') as (country:chararray, product:chararray, c:int);
g = group data by country;
result = foreach g {
    prods = order data by c desc;
    top_prods = limit prods 1;
    generate flatten(top_prods);
}
dump result;

这组由第一列的输入,然后在嵌套的foreach它通过订单数每组产品,然后采取第一(最高数)。

This groups the input by first column, then in the nested foreach it orders the products per group by count, then takes the first (highest count).

输出:

(latin america,prod1,48)
(south America,prod1,45)

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

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