如何根据 Pig/Hive 中的关键子集进行聚合?
How to aggregate on the basis of key subset in Pig/Hive?
我有以下数据集,其中 emp_id、org_id 和 res_id 是关键列
Input data is -
emp_id | org_id | res_id | emp_sal
123 | 345 | 678 | 10000
123 | | 678 | 20000
123 | 345 | | 30000
| 345 | 678 | 10000
103 | 305 | 608 | 40000
103 | | | 50000
如果剩余记录是完整键的子集,我需要聚合 emp_sal。例如 "123 | 345 | 678 |" 在输入数据集中多了 3 个子集。
Expected output is -
emp_id | org_id | res_id | emp_sal
123 | 345 | 678 | 70000
103 | 305 | 608 | 90000
如何在 Pig 中计算此聚合?
SELECT c.emp_id,
c.org_id,
c.res_id,
Sum(d.emp_sal)
FROM (SELECT DISTINCT emp_id,
org_id,
res_id
FROM emptest
WHERE emp_id IS NOT NULL
AND org_id IS NOT NULL
AND res_id IS NOT NULL) AS c,
emptest AS d
WHERE d.emp_id = c.emp_id
OR d.org_id = c.org_id
OR d.res_id = c.res_id
GROUP BY c.emp_id,
c.org_id,
c.res_id;
以上 Hive 查询可以帮到您。
我有以下数据集,其中 emp_id、org_id 和 res_id 是关键列
Input data is -
emp_id | org_id | res_id | emp_sal
123 | 345 | 678 | 10000
123 | | 678 | 20000
123 | 345 | | 30000
| 345 | 678 | 10000
103 | 305 | 608 | 40000
103 | | | 50000
如果剩余记录是完整键的子集,我需要聚合 emp_sal。例如 "123 | 345 | 678 |" 在输入数据集中多了 3 个子集。
Expected output is -
emp_id | org_id | res_id | emp_sal
123 | 345 | 678 | 70000
103 | 305 | 608 | 90000
如何在 Pig 中计算此聚合?
SELECT c.emp_id,
c.org_id,
c.res_id,
Sum(d.emp_sal)
FROM (SELECT DISTINCT emp_id,
org_id,
res_id
FROM emptest
WHERE emp_id IS NOT NULL
AND org_id IS NOT NULL
AND res_id IS NOT NULL) AS c,
emptest AS d
WHERE d.emp_id = c.emp_id
OR d.org_id = c.org_id
OR d.res_id = c.res_id
GROUP BY c.emp_id,
c.org_id,
c.res_id;
以上 Hive 查询可以帮到您。