1
votes

This is my output file, which I wrote out with another Pig script:

1   3,5 
2   4,6,7

I'm trying to parse each line as (chararray, tuple)

data = load 'test45'  as (x:chararray, y:tuple());

But when I try to dump the tuples, they're empty:

rows = foreach data generate y;

() ()

1

1 Answers

1
votes

try this.

   X = LOAD 'pigtuple.txt' AS (str:chararray);

   X1 = FOREACH X GENERATE FLATTEN(STRSPLIT(str, '\\s+')) AS (id:int, attr:chararray);

   X3 = FOREACH X1 GENERATE id, STRSPLIT(attr, ',') AS (y:tuple());

   X4 = foreach X3 GENERATE id,y;

   dump X4;

if you want access each element in tuple.

   X4 = foreach X3 GENERATE y.$0,y.$1;