0

My current table structure has the following columns:

id, name, height, weight

I need to un-pivot it so that a single id will have 2 entries - one for height and one for weight. The query would be like this in Hive:

select id, name, "height" attribute, height as value
from table1
union all
select id, name, "weight" attribute, height as value
from table1

How do I do this in Pig?

o-90
  • 17,045
  • 10
  • 39
  • 63
Maharaj
  • 87
  • 3
  • 11

1 Answers1

0

Not exactly a duplicate, but close to: Pivot table with Apache Pig.

Here is a solution.

BTW, I am assuming you had a typo in line 4 of your query.

raw = load 'data.txt' as (id, name, height, weight);
a = foreach raw generate id, name, TOBAG(('height', height), ('weight', weight)) as vbag;
b = foreach a {
generate id, name, flatten(vbag);
};
dump b;
Community
  • 1
  • 1
Brice
  • 346
  • 4
  • 14