I am at some very early stages of learning Pig/Pig Latin, so forgive the lack of knowledge. If we had a dataset that was in the format of something like:
fname, lname, month, pay, emp_category
Bob, Smith, January, 2000, non-manager
Bob, Smith, February, 2000, non-manager
John, Doe, January, 4500, manager
John, Doe, February, 4500, manager
I see how I would total each employee's pay up , put what if I wanted to create a dataset that also subtracts each employees total pay from each other employee's total pay:
Bob, Smith 4000, non-manager, John Doe, 9000, manager, 5000
With SQL I would probably just create two temp tables with:
SELECT fname, lname, sum(pay) as total_pay_m WHERE category = 'manager' INTO M_table FROM TABLE_NAME;
SELECT fname, lname, sum(pay) as total_pay_nm WHERE category = 'non_manager' INTO NM_table FROM TABLE_NAME;
SELECT *, ABS(total_pay_nm - total_pay_m) as PayDiff FROM M_table, NM_table WHERE M_table.fname <> NM_table.fname and M_table.lname <> NM_table.lname;
The SQL might not be perfect, but I hope the point is understood, but any assistance on achieving this with Pig would be appreciated.