Say I have a relation as follow:
(A, (1, 2, 3)) (B, (2, 3))
Is it possible to make a new relation by expanding the bag element as follow using Pig Latin?
(A, 1) (A, 2) (A, 3) (B, 2) (B, 3)
I tried using FOREACH
and GENERATE
, but I am having difficulty generating a new tuple while looping through a bag element.
Thanks,
------------- EDIT -------------
Here's a sample input:
A 1 2 3 B 2 3
Separated by tab and then a whitespace.
I used STRSPLIT
to handle whitespace to generate a tuple.
raw_x = LOAD './sample.txt' using PigStorage('\t') AS (title:chararray, links:chararray); data_x = FOREACH raw_x GENERATE title, STRSPLIT(links, '\\s+') AS links;