Juan John Mathews
Juan John Mathews

Reputation: 736

Concatenate fields from different relations

There are two relations

r1: {f1: chararray, f2: chararray}
r2: {f3: chararray, f4: chararray}

There is no unique key in either of the relations, but the number of tuples are the same.

Is there a way to concatenate the corresponding fields of the relations to get an output like f2, f4 ?

Upvotes: 1

Views: 114

Answers (2)

Murali Rao
Murali Rao

Reputation: 2287

Another alternative would be to use : CROSS (http://pig.apache.org/docs/r0.12.0/basic.html#cross)

Note : Extract from Docs : CROSS is an expensive operation and should be used sparingly.

Pig Script :

R1 = LOAD 'a.csv'  USING  PigStorage(',') AS (f1:chararray,f2:chararray);
R2 = LOAD 'b.csv'  USING  PigStorage(',') AS (f3:chararray,f4:chararray);

R3 = CROSS R1,R2;

R4 = FOREACH R3 GENERATE f2,f4;

DUMP R4;

Inputs :

a.csv :

f1_value,f2_value

b.csv

f3_Value,f4_value

Output : DUMP R4 :

(f2_value,f4_value)

Upvotes: 0

glefait
glefait

Reputation: 1691

If the tuples are in the right order, you can use RANK.

r1a = RANK r1 BY * DENSE;
r2a = RANK r2 BY * DENSE;

r1r2 = JOIN r1a BY $0, r2a BY $0;

Upvotes: 3

Related Questions