当前位置:K88软件开发文章中心大数据Apache Pig → 文章内容

Apache Pig Join运算符

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-26 10:03:42

:00:00,3,1500)(3,kaushik,23,Kota,2000,102,2009-10-08 00:00:00,3,3000)(4,Chaitali,25,Mumbai,6500,103,2008-05-20 00:00:00,4,2060)Full Outer Join(全外连接)当一个关系中存在匹配时,full outer join操作将返回行。语法下面给出使用 JOIN 运算符执行full outer join的语法。grunt> outer_full = JOIN customers BY id FULL OUTER, orders BY customer_id;例让我们对customers和orders执行full outer join操作,如下所示。grunt> outer_full = JOIN customers BY id FULL OUTER, orders BY customer_id;验证使用 DUMP 运算符验证关系 outer_full ,如下所示。grun> Dump outer_full; 输出它将产生以下输出,显示关系 outer_full 的内容。(1,Ramesh,32,Ahmedabad,2000,,,,)(2,Khilan,25,Delhi,1500,101,2009-11-20 00:00:00,2,1560)(3,kaushik,23,Kota,2000,100,2009-10-08 00:00:00,3,1500)(3,kaushik,23,Kota,2000,102,2009-10-08 00:00:00,3,3000)(4,Chaitali,25,Mumbai,6500,103,2008-05-20 00:00:00,4,2060)(5,Hardik,27,Bhopal,8500,,,,)(6,Komal,22,MP,4500,,,,)(7,Muffy,24,Indore,10000,,,,)使用多个Key我们可以使用多个key执行JOIN操作。语法下面是如何使用多个key对两个表执行JOIN操作。grunt> Relation3_name = JOIN Relation2_name BY (key1, key2), Relation3_name BY (key1, key2);假设在HDFS的 /pig_data/ 目录中有两个文件,即 employee.txt 和 employee_contact.txt ,如下所示。 employee.txt 001,Rajiv,Reddy,21,programmer,003002,siddarth,Battacharya,22,programmer,003003,Rajesh,Khanna,22,programmer,003004,Preethi,Agarwal,21,programmer,003005,Trupthi,Mohanthy,23,programmer,003006,Archana,Mishra,23,programmer,003007,Komal,Nayak,24,teamlead,002008,Bharathi,Nambiayar,24,manager,001 employee_contact.txt 001,9848022337,Rajiv@gmail.com,Hyderabad,003002,9848022338,siddarth@gmail.com,Kolkata,003003,9848022339,Rajesh@gmail.com,Delhi,003004,9848022330,Preethi@gmail.com,Pune,003005,9848022336,Trupthi@gmail.com,Bhuwaneshwar,003006,9848022335,Archana@gmail.com,Chennai,003007,9848022334,Komal@gmail.com,trivendram,002008,9848022333,Bharathi@gmail.com,Chennai,001将这两个文件加载到Pig中,通过关系 employee 和 employee_contact ,如下所示。grunt> employee = LOAD 'hdfs://localhost:9000/pig_data/employee.txt' USING PigStorage(',') as (id:int, firstname:chararray, lastname:chararray, age:int, designation:chararray, jobid:int); grunt> employee_contact = LOAD 'hdfs://localhost:9000/pig_data/employee_contact.txt' USING PigStorage(',') as (id:int, phone:chararray, email:chararray, city:chararray, jobid:int);现在,让我们使用 JOIN 运算符连接这两个关系的内容,如下所示。grunt> emp = JOIN employee BY (id,jobid), employee_contact BY (id,jobid);验证使用 DUMP 运算符验证关系 emp ,如下所示。grunt> Dump emp; 输出它将产生以下输出,显示名为 emp 的关系的内容,如下所示。(1,Rajiv,Reddy,21,programmer,113,1,9848022337,Rajiv@gmail.com,Hyderabad,113)(2,siddarth,Battacharya,22,programmer,113,2,9848022338,siddarth@gmail.com,Kolka ta,113) (3,Rajesh,Khanna,22,programmer,113,3,9848022339,Rajesh@gmail.com,Delhi,113) (4,Preethi,Agarwal,21,programmer,113,4,9848022330,Preethi@gmail.com,Pune,113) (5,Trupthi,Mohanthy,23,programmer,113,5,9848022336,Trupthi@gmail.com,Bhuwaneshw ar,113) (6,Archana,Mishra,23,programmer,113,6,9848022335,Archana@gmail.com,Chennai,113) (7,Komal,Nayak,24,teamlead,112,7,9848022334,Komal@gmail.com,trivendram,112) (8,Bharathi,Nambiayar,24,manager,111,8,9848022333,Bharathi@gmail.com,Chennai,111)

上一页  [1] [2] 


Apache Pig Join运算符