ohana
ohana

Reputation: 285

Pig: how to split array

i have a tuple like this:

((item114,),1)
((item32,item31,),1)
((item81,item27,),2)

the last number is the frequency of the item,so item114 has freq. of 1, item 81 has freq. of 2, now i want to split it to tuple of the format: (item#, freq.), so the result would be:

 (item114, 1)
 (item32, 1)
 (item31, 1)
 (item81, 2)
 (item27, 2)

how can i do that? Thanks.

Upvotes: 0

Views: 2232

Answers (1)

phoenix24
phoenix24

Reputation: 2102

You could essentially flatten out the relation, which shall give you the desired tuple. For example, let C describe the above relation which is as follows,

C = GROUP input by A;

describe C;
C: {group: int, input: {i: int,j: int,k: int}}

dump C;
({(item114,)},1)

d = foreach c generate group, flatten(a.i);

describe d;
d: {group: int,i::i: int}

dump d;
(item114, 1)
(item32, 1)

Upvotes: 1

Related Questions