Apr 1, 2016

Apache Pig Exercises: 27 List Employee names starting with 'S' and ending 'H' with 5 characters length



In this post the sample Apache Pig script will List Employee names starting with 'S' and ending 'H' with 5 characters length.

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 Employee names with 3rd character as ‘R’ and four characters length:


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) AND (STARTSWITH(ename,'S') == true) AND ENDSWITH(ename,'H') == true);
rec_ordr = order rec_fltr by sal;
dump rec_fltr;

@Apache Pig Output on Grunt Shell:  

(7369,SMITH,true,true,5,CLERK,7902,1980-12-17,800.0,,20)

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


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

0 comments:

Post a Comment