Andi Maier
Andi Maier

Reputation: 1034

Hadoop Pig Max - Not correct output

I am having some trouble with an apparently simple PIG MAX function which does not work for me. I did a grouping where I calculated a sum.

C3 = FOREACH C2 GENERATE group, SUM(C1.figures);

I receive the following output

(Peter, 345)
(Paul, 459)
(Andi, 500)

Now I want to get the max value so that the output is

(Andi, 500)

I am trying the following code

 C4 = FOREACH C3 GENERATE $0 as (id: chararray), $1 as (id2:long);
 C5 = GROUP C4 ALL;
 C6 = FOREACH C5 GENERATE C4.id, MAX(C4.id2);

But as output I am getting

 ({Peter, Paul, Andi}, 500)

which is not what I wanted.

Can anybody help? Would be much appreciated

cheers, Andi

Upvotes: 0

Views: 42

Answers (1)

Andi Maier
Andi Maier

Reputation: 1034

Solved it via
sort = ORDER C4 by id2 DESC;
limit = LIMIT sort 1;

Upvotes: 1

Related Questions