4

I've been trying to figure out how to cogroup for a long time, and I can never seem to get it to work. The code below should just give two numbers, one from each dataset. My end goal would be to subtract one from the other, but I can't seem to do that using cogroup because I always receive the Unknown IDTOKEN error. Any suggestions?

q = load "Opportunities_Sales_Ops";
q = group q by all;
q = foreach q generate sum('Total_MRR__c') as 'B';
p = foreach q generate 'B', 'B'*0  as 'zero';

q = load "ServiceOrders_JL";
q = group q by all;
q = foreach q generate sum('Total_MRR__c') as 'A';
q = foreach q generate 'A', 'A'*0  as 'zero';

z = cogroup p by 'zero', q by 'zero';
z = foreach z generate p.'B' as 'Gross Sales', q.'A' as 'Cancelled Sales', q.'B'-p.'A' as 'Net Sales';

I receive the error "Unknown IDTOKEN: B", but I've very clearly created B above. Can anyone provide some suggestions?

1

I believe you need to include an aggregation in your last generate statement.

What happens if you try this:

z = foreach z generate sum(p.'B') as 'Gross Sales', sum(q.'A') as 'Cancelled Sales', sum(q.'B')-sum(p.'A') as 'Net Sales';
| improve this answer | |
  • Super helpful for my case. Unclear on why that works when it's summing a single value. – Jim Meyer Jun 22 '19 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.