Jan 19, 2016

Apache Pig Exercises: 6. List all employees who are ‘Managers’


In this post the sample Apache Pig script will display all Employee who are Managers.

The examples and exercise scripts are created using Apache Pig current version r0.14.0.

@ Test data structure:
Please refer to Apache Pig learning series intro... post for the file structures, visit the reference section shown at the bottom of the post for more. 

@ Sample data:

Employees data table:


Department data table:


@ Apache Pig Script:

List all employee records who are Managers:

grunt> 
/* load data file in pig reference variable */
data = LOAD '/Documents/tbl_EMP.txt' USING PigStorage(',') as (empno:int, ename:chararray, job:chararray, mgr:int, hiredate:chararray, sal:float, comm:float, deptno:int);
all_recs = foreach data generate empno,ename,job,mgr,hiredate,sal,comm,deptno;
fltr_mgrs = filter all_recs by job=='MANAGER' ;
dump fltr_mgrs;

@Apache Pig Output on Grunt Shell: 


(7566,JONES,MANAGER,7839,1981-04-02,2975.0,,20)
(7698,BLAKE,MANAGER,7839,1981-05-01,2850.0,,30)

(7782,CLARK,MANAGER,7839,1981-06-09,2450.0,,10)

@ Apache Pig Reference/s:
  • https://pig.apache.org
  • http://pig.apache.org/docs/r0.14.0/
_________________
Thank you!

0 comments:

Post a Comment