In this post the sample Apache Pig script will display Empno, Ename, Job, Hiredate, Experience of all 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 Empno, Ename, Job, Hiredate, Experience of all Managers:
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, (int)GetYear(CurrentTime()) - (int)SUBSTRING(hiredate,0,4) as expn ,sal , comm,deptno;
fltr_mgrs = filter all_recs by job == 'MANAGER';
dump fltr_mgrs;
(7566,JONES,MANAGER,7839,1981-04-02,35,2975.0,,20)
(7698,BLAKE,MANAGER,7839,1981-05-01,35,2850.0,,30)
(7782,CLARK,MANAGER,7839,1981-06-09,35,2450.0,,10)
- https://pig.apache.org
- http://pig.apache.org/docs/r0.14.0/
Thank you!
0 comments:
Post a Comment