首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >猪加入的独特性

猪加入的独特性
EN

Stack Overflow用户
提问于 2014-03-26 21:11:48
回答 1查看 141关注 0票数 0

我有两张桌子:

Name_SSN和Phone_Address

Name_SSN包含Joe。

Phone_Address Joe999-999-9990日落佛罗里达乔999-9991日落佛罗里达吉姆999 999-9994 Sunny CA Jim 999 999 9994 Sunny CA Bob 999-9999-9999罗利VA

我想加入并得到: Joe

我对猪不熟悉,也不懂.

谢谢你的帮助,

克里斯

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-27 03:04:33

听起来你想在猪身上做一个内部连接。下面的代码应该对您有帮助:

NameSSNAddr.pig

代码语言:javascript
复制
--Load the two data files
namessn = LOAD 'Name_SSN.csv' USING PigStorage(',') AS (name:chararray, ssn:chararray);
phoneaddr = LOAD 'Phone_Address.csv' USING PigStorage(',') AS (name:chararray, phone:chararray, address:chararray);

--Perform the join of the two datasets on the "name" field
data_join = JOIN namessn BY name, phoneaddr BY name;

--The join combined all fields from both datasets.  
--We just want a few fields, so generate them specifically.
data = FOREACH data_join GENERATE namessn::name AS name, namessn::ssn AS ssn, phoneaddr::address AS address;

--You didn't say if you wanted the data distinct or not.
--If you want only one row per distinct user, use this alias.
data_distinct = DISTINCT data;

--Dump all of the aliases so you can see what's in them.
dump namessn;
dump phoneaddr;

dump data;
dump data_distinct;

来自dump namessn输出

代码语言:javascript
复制
(Joe,xxx-xx-xxx1)
(Jim,xxx-xx-xxx2)
(Bob,xxx-xx-xxx3)

来自dump phoneaddr的输出

代码语言:javascript
复制
(Joe,999-999-9990,Sunset Florida)
(Joe,999-999-9991,Sunset Florida)
(Joe,999-999-9992,Sunset Florida)
(Jim,999-999-9994,Sunny CA)
(Jim,999-999-9994,Sunny CA)
(Bob,999-999-9999,Raleigh VA)

来自dump data的输出

代码语言:javascript
复制
(Bob,xxx-xx-xxx3,Raleigh VA)
(Jim,xxx-xx-xxx2,Sunny CA)
(Jim,xxx-xx-xxx2,Sunny CA)
(Joe,xxx-xx-xxx1,Sunset Florida)
(Joe,xxx-xx-xxx1,Sunset Florida)
(Joe,xxx-xx-xxx1,Sunset Florida)

来自dump data_distinct的输出

代码语言:javascript
复制
(Bob,xxx-xx-xxx3,Raleigh VA)
(Jim,xxx-xx-xxx2,Sunny CA)
(Joe,xxx-xx-xxx1,Sunset Florida)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22673147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档