Apr 4, 2016

Apache Pig Exercises: 33 List all employees except ‘President’ & ‘Manager’ in asc order of salaries



In this post the sample Apache Pig script will List all employees except ‘President’ & ‘Manager’ in asc order of salaries

Using Apache Pig version r0.15.0.


@ Test data structure:
Please refer to APACHE PIG ~ ALL SAMPLE TABLES and STRUCTURES post for the file structures, visit the reference section shown at the bottom of the post for more. 


@ Sample data:

Employees data table:


@ Apache Pig Script:

a) List all employees except ‘President’ & ‘Manager’ in asc order of salaries:

WIP

grunt> 
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;
rec_fltr = filter all_recs by ( job != 'MANAGER' AND job != 'PRESIDENT') ;
rec_ordr = order rec_fltr by sal;
dump rec_ordr;


@Apache Pig Output on Grunt Shell:  

(7369,SMITH,5,CLERK,7902,1980-12-17,800.0,,20)
(7900,JAMES,5,CLERK,7698,1981-12-03,950.0,,30)
(7876,ADAMS,5,CLERK,7788,1983-01-12,1100.0,,20)
(7654,MARTIN,6,SALESMAN,7698,1981-09-28,1250.0,1400.0,30)
(7521,WARD,4,SALESMAN,7698,1981-02-22,1250.0,500.0,30)
(7934,MILLER,6,CLERK,7782,1982-01-23,1300.0,,10)
(7844,TURNER,6,SALESMAN,7698,1981-09-08,1500.0,0.0,30)
(7499,ALLEN,5,SALESMAN,7698,1981-02-20,1600.0,300.0,30)
(7902,FORD,4,ANALYST,7566,1981-12-03,3000.0,,20)
(7788,SCOTT,5,ANALYST,7566,1982-12-09,3000.0,,20)

----------------------------------------------------------------------------------------------------------------------------------------------------------



@ Apache Pig Reference/s:
  • https://pig.apache.org
  • http://pig.apache.org/docs/r0.15.0/

0 comments:

Post a Comment