0

我有两个 CSV 文件:

1- Fertiltiy.csv:

在此处输入图像描述

2- 预期寿命.csv:

在此处输入图像描述

我想加入他们的猪,结果会是这样的:

在此处输入图像描述

我是猪新手,我无法得到正确的答案,但这是我的代码:

fertility = LOAD 'fertility' USING org.apache.hcatalog.pig.HCatLoader();

lifeExpectency = LOAD 'lifeExpectency' USING   org.apache.hcatalog.pig.HCatLoader();

A = JOIN fertility by country, lifeExpectency by country; 

B = JOIN fertility by year, lifeExpectency by year; 

C = UNION A,B;

DUMP C; 

这是我的代码的结果:

在此处输入图像描述

4

1 回答 1

2

您可以按国家和年份加入,并选择最终输出所需的必要列。

fertility = LOAD 'fertility' USING org.apache.hcatalog.pig.HCatLoader();
lifeExpectency = LOAD 'lifeExpectency' USING   org.apache.hcatalog.pig.HCatLoader();

A = JOIN fertility by (country,year), lifeExpectency by (country,year); 
B = FOREACH A GENERATE  fertility::country,fertility::year,fertility::fertility,lifeExpectency::lifeExpectency;  
DUMP B; 
于 2017-10-22T16:50:02.580 回答