Search code examples
apache-pigtranspose

Transpose in Apache Pig


I have input like below

name,gender,salary,city  -- header
John,male,4000,NY

How can I transpose column to rows in Pig? I need an output like below.

name,field1,value
John,gender,male
John,salary,4000
John,city,NY

In Hive, I can create a map and explode it into two columns, but in Pig I don't know how to achieve this. Can anyone help me with an approach?


Solution

  • Possible answer to this is using UDF that will recieve each row and input schema and than generate bag of tuples, each containing one of the values for each of fields. After call to UDF you can use flatten to achieve the required form of result