0

I have input data as:

Abhinav,10K
Abhinav,20K
Abhinav,30K
Nitin,15K
Nitin,25K
Mohit,50K

I need final output as:

(Abhinav,10K,20K,30K)
(Nitin,15K,25K)
(Mohit,50K)

I have come till this intermediate point:

(Abhinav,{(10K),(20K),(30K)})
(Mohit,{(50K)})
(Nitin,{(15K),(25K)})

Also, is there any way to convert this intermediate point to final solution.

Abhinav Singh
  • 109
  • 1
  • 2
  • 10
  • You need to flatten the intermediate point to reach the final output. Look into this: https://stackoverflow.com/questions/11213567/pivot-table-with-apache-pig?rq=1 – gonephishing Aug 17 '16 at 12:41
  • TOBAG and TOTUPLE will help you to get this result. you can also refer this : https://stackoverflow.com/questions/27492700 – Bector Aug 17 '16 at 12:54
  • @Bector : I don't have intermediate column NAME so I am able to get desired output. – Abhinav Singh Aug 17 '16 at 14:02
  • @gonephishing : flatten is not working because I need only 1 row for Abhinav instead of this flatten is creating 3 rows. – Abhinav Singh Aug 17 '16 at 14:04
  • I got the desired result through this link. Thanks!! [link]http://stackoverflow.com/questions/21917709/pig-transform-data-from-rows-to-columns-while-inserting-placeholders-for-non-e – Abhinav Singh Aug 17 '16 at 14:23

1 Answers1

0

Somehow I got the answer and it's very easy!

 NameSal = LOAD '/home/asingh50/NameSalary.txt' USING PigStorage(',') AS(name:chararray,salary:chararray);
 NameSalGroup = GROUP NameSal by (name);
 NameSalResult = FOREACH NameSalGroup GENERATE group AS Name, BagToString(NameSal.salary, ',') as salary:chararray;
Abhinav Singh
  • 109
  • 1
  • 2
  • 10