[Solved-2 Solutions] Pivot table with Apache Pig ?
This is related to the question in Pivot table with Apache Pig.
Input data as
and need to pivot and get the output as
How to do it in Pig ?
It can be done in 2 ways:
1. Write a UDF which returns a bag of tuples. It will be the most flexible solution, but requires Java code.
2. Write a rigid script like this below:
Running this script gives following results:
- We can remove col3 from id 1 to show how to handle optional data
- Id Name Value 1 Column1 Row11 1 Column2 Row12 2 Column1 Row21 2 Column2 Row22 2 Column3 Row23
Here is the code using pigscript