...

Big Data - Apache Pig

Back to Course

Lesson Description


Lession - #472 Apache pig ORDER BY Operator


The ORDER BY operator is utilized to display the items in a relation in an sorted order based on least one fields.

The syntax of ORDERBY Operator operator is shown below:


 
 grunt> Relation_name2 = ORDER Relatin_name1 BY (ASC|DESC>
;


Example

Assume that we have a file named student_details.txt in the HDFS directory /pig_data/ as shown below.

1 aaa 74385738 delhi
2 bbb 76349948 mumbai
3 ddd 87493589 pune
4 ggg 74824727 goa
5 hhh 74843847 pune
6 uuu 76347242 delhi


Writing ORDERBY Operator


grunt> order_by_data = ORDER student_details BY id DESC;
 
Output



6 uuu 76347242 delhi
5 hhh 74843847 pune
4 ggg 74824727 goa
3 ddd 87493589 pune
2 bbb 76349948 mumbai
1 aaa 74385738 delhi