6

如何MAX在 Pig 中找到元组的 ?

我的代码如下所示:

A,20
B,10
C,40
D,5

data = LOAD 'myData.txt' USING PigStorage(',') AS key, value;
all = GROUP data ALL;
maxKey = FOREACH all GENERATE MAX(data.value);
DUMP maxKey;

这将返回 40,但我想要完整的键值对:C,40. 有任何想法吗?

4

2 回答 2

7

这适用于猪 0.10.0:

data = LOAD 'myData.txt' USING PigStorage(',') AS (key, value: long);
A = GROUP data ALL;
B = FOREACH A GENERATE MAX(data.value) AS val;
C = FILTER data BY value == (long)C.val;
DUMP C;
于 2012-12-27T15:32:11.313 回答
3

试试这个:

data = LOAD 'myData.txt' USING PigStorage(',') AS (key: chararray, value: int);

sorted = ORDER data BY value DESC;

limited = LIMIT sorted 1;

projected = FOREACH limited GENERATE key;

DUMP projected;
于 2013-02-01T13:37:14.927 回答