apache pig - Pig - Convert rows into multiple columns -
here 1 naive solution.
grouping every 3 rows using rank
, group
, , filter
each of 3 conditions.
my pig script
a = load '/path_to_data/data' (c1 : chararray); b = rank a; c = foreach b generate (rank_a+2)/3 id, c1; d = foreach (group c id) { 1 = filter c c1 matches 'one:.*'; 2 = filter c c1 matches 'two:.*'; 3 = filter c c1 matches 'three:.*'; generate group id , flatten(one.c1) c1_one , flatten(two.c1) c1_two , flatten(three.c1) c1_three ; }; dump d;
my result
(1,one:"a",two:"2",three:"last") (2,one:"b",two:"1",three:"first")
Comments
Post a Comment