如何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
. 有任何想法吗?
如何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
. 有任何想法吗?
这适用于猪 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;
试试这个:
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;