What I want to do is to sum values of a field in all rows in an alias. This must be simple but somehow I can't find the answer. This is probably because what I want is a scalar value while PIG handles datasets? I guess I can create a row with a field which is the sum? Please advise!
How to compute sum of a field in all the rows from an alias
Asked Answered
I found an answer but I don't have enough reputation to answer my own question in 8 hours after posting. I will add my answer later tonight. –
Gaylagayle
This can be achieved using a GROUP ALL to bring everything into a single group, and then the SUM function to add together all the fields:
DESCRIBE a
a: (name, age, height)
b = GROUP a ALL;
c = FOREACH b GENERATE SUM(a.age);
Exactly. That was what I found. Thanks anyway! –
Gaylagayle
© 2022 - 2024 — McMap. All rights reserved.