DISTINCT 运算符用于从关系中删除多余(重复)元组.
语法
给定以下是 DISTINCT 运算符的语法.
grunt> Relation_name2 = DISTINCT Relatin_name1;
示例
假设我们在HDFS中有一个名为 student_details.txt 的文件目录/pig_data/如下所示.
student_details.txt
001,Rajiv,Reddy,9848022337,Hyderabad002,siddarth,Battacharya,9848022338,Kolkata 002,siddarth,Battacharya,9848022338,Kolkata 003,Rajesh,Khanna,9848022339,Delhi 003,Rajesh,Khanna,9848022339,Delhi 004,Preethi,Agarwal,9848022330,Pune 005,Trupthi,Mohanthy,9848022336,Bhuwaneshwar006,Archana,Mishra,9848022335,Chennai 006,Archana,Mishra,9848022335,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, phone:chararray, city:chararray);
现在让我们使用 DISTINCT 从名为 student_details 的关系中删除多余(重复)元组运算符,并将其存储为另一个名为 distinct_data 的关系,如下所示.
grunt> distinct_data = DISTINCT student_details;
验证
使用 DUMP distinct_data >运算符如下所示.
grunt> Dump distinct_data;
输出
它将产生以下输出,显示关系 distinct_data 如下.
(1,Rajiv,Reddy,9848022337,Hyderabad)(2,siddarth,Battacharya,9848022338,Kolkata) (3,Rajesh,Khanna,9848022339,Delhi) (4,Preethi,Agarwal,9848022330,Pune) (5,Trupthi,Mohanthy,9848022336,Bhuwaneshwar)(6,Archana,Mishra,9848022335,Chennai)