How do I find the MAX
of a tuple in Pig?
My code looks like this:
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;
This returns 40, but I want the full key-value pair: C,40
. Any ideas?
This works with Pig 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;
Try this:
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With