Reputation: 41
I have a relation which contains 7 fields and want to convert into below output.
Input :
(x,y,10,z,20,a,30) ->(chararray,chararray,double,chararray,double,chararray,double)
Output should be like below..
(x,y,10)
(x,z,20)
(x,a,30)
Could you please let any one know how to achieve this.....
Upvotes: 0
Views: 176
Reputation: 11080
You have used the right function TOBAG.TOBAG(*) means apply TOBAG on all fields. CONCAT the fields that needs to be converted to rows and then FLATTEN the concatenated fields.
Note:You are using double for few fields,so you will see decimal precision with the fields that are loaded as double.
A = LOAD 'test7.txt' USING PigStorage(',') AS (f1:chararray,f2:chararray,f3:double,f4:chararray,f5:double,f6:chararray,f7:double);
B = FOREACH A GENERATE f1,FLATTEN(TOBAG(CONCAT(f2,CONCAT(',',(chararray)f3)),CONCAT(f4,CONCAT(',',(chararray)f5)),CONCAT(f6,CONCAT(',',(chararray)f7))));
DUMP B;
Upvotes: 1