Jan 26, 2016

Apache Pig Exercises: 21. List Employees those are having five characters in their names



In this post the sample Apache Pig script will List employees wthose are having five characters in their names.

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

@ Test file 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:

a) List employees wthose are having five characters in their names.

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 (SIZE(ename)==5) ;
rec_ordr = order rec_fltr by sal;
dump rec_ordr;

@Apache Pig Output on Grunt Shell:

(7369,SMITH,CLERK,7902,1980-12-17,800.0,,20)
(7900,JAMES,CLERK,7698,1981-12-03,950.0,,30)
(7876,ADAMS,CLERK,7788,1983-01-12,1100.0,,20)
(7499,ALLEN,SALESMAN,7698,1981-02-20,1600.0,300.0,30)
(7782,CLARK,MANAGER,7839,1981-06-09,2450.0,,10)
(7698,BLAKE,MANAGER,7839,1981-05-01,2850.0,,30)
(7566,JONES,MANAGER,7839,1981-04-02,2975.0,,20)
(7788,SCOTT,ANALYST,7566,1982-12-09,3000.0,,20)

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

_________________
Thank you!

0 comments:

Post a Comment