Jan 19, 2016

Apache Pig Exercises: 7. List all the unique job title in a descending order


In this post the sample Apache Pig script will display all unique job title in a descending order.

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 display all unique job title in a descending order:

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_jobs = foreach data generate job;
uniq_jobs = distinct all_jobs;
ordr_job = order uniq_jobs by job desc; 
dump ordr_job;

@Apache Pig Output on Grunt Shell: 


(SALESMAN)
(PRESIDENT)
(MANAGER)
(CLERK)

(ANALYST)


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

0 comments:

Post a Comment