1

im new at programming in Pig Latin and i have a question.

Let's say i have the following two relations (A and B):

Relation A: https://i.stack.imgur.com/Aa5Rd.png

Relation B: https://i.stack.imgur.com/m467q.png

Now, the Relations should be joined, but only when in A a key (id) exists. Otherwise not. So the Result should look like:

Relation Result: i.stack.imgur.com/3elgh.png (i cannot post more than 2 links)

How i can solve that?

My approach result = JOIN A BY id, B BY id; because it creates a result relation with all ids & texts :/

Thank you very much in advance,

Stefanos

Sivasakthi Jayaraman
  • 4,724
  • 3
  • 17
  • 27
Stefanos13
  • 129
  • 1
  • 1
  • 11

1 Answers1

0

Your approach is right. I got the correct output as you mentioned but not sure why you didn't get the output. Can you cross check your pigscript with the below one?

input1:

1
4
6

input2:

1,peter
2,jay
3,dan
4,knut
5,Gnu
6,rafael
7,hans

PigScript:

A = LOAD 'input1' AS (id:int);
B = LOAD 'input2' USING PigStorage(',') AS (id:int,text:chararray);
C = JOIN A BY id,B BY id;
D = FOREACH C GENERATE A::id AS id,B::text as text;
DUMP D;

Output:

(1,peter)
(4,knut)
(6,rafael)
Sivasakthi Jayaraman
  • 4,724
  • 3
  • 17
  • 27