📜  Apache Pig-订购依据

📅  最后修改于: 2020-12-02 05:37:56             🧑  作者: Mango


ORDER BY运算符用于基于一个或多个字段按排序顺序显示关系的内容。

句法

下面给出的是ORDER BY运算符的语法。

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

假设我们在HDFS目录/ pig_data /中有一个名为student_details.txt的文件,如下所示。

student_details.txt

001,Rajiv,Reddy,21,9848022337,Hyderabad
002,siddarth,Battacharya,22,9848022338,Kolkata
003,Rajesh,Khanna,22,9848022339,Delhi 
004,Preethi,Agarwal,21,9848022330,Pune 
005,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar 
006,Archana,Mishra,23,9848022335,Chennai 
007,Komal,Nayak,24,9848022334,trivendram 
008,Bharathi,Nambiayar,24,9848022333,Chennai

并将该文件加载到Pig中,其关系名称为Student_details ,如下所示。

grunt> student_details = LOAD 'hdfs://localhost:9000/pig_data/student_details.txt' USING PigStorage(',')
   as (id:int, firstname:chararray, lastname:chararray,age:int, phone:chararray, city:chararray);

现在,让我们根据学生的年龄按降序对关系进行排序,并使用ORDER BY运算符将其存储到另一个名为order_by_data的关系中,如下所示。

grunt> order_by_data = ORDER student_details BY age DESC;

验证

使用DUMP运算符验证关系order_by_data ,如下所示。

grunt> Dump order_by_data; 

输出

它将产生以下输出,显示关系order_by_data的内容。

(8,Bharathi,Nambiayar,24,9848022333,Chennai)
(7,Komal,Nayak,24,9848022334,trivendram)
(6,Archana,Mishra,23,9848022335,Chennai) 
(5,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar)
(3,Rajesh,Khanna,22,9848022339,Delhi) 
(2,siddarth,Battacharya,22,9848022338,Kolkata)
(4,Preethi,Agarwal,21,9848022330,Pune) 
(1,Rajiv,Reddy,21,9848022337,Hyderabad)