Skip to content Skip to sidebar Skip to footer

Manipulating A Data Structure In Pig/Hive

I'm not really sure how to phrase this question, so please redirect me if there is a better place for this question. Right now I have a data structure, more or less organized like

Solution 1:

I am not sure if this will work in Hive. I know it is pretty similar to SQL. Give it a try.

select item, year,
'Jan' as Month,
Jan as value
from yourtable
UNION
select item, year,
'Feb' as Month,
Feb as value
from yourtable
UNION
select item, year,
'Mar' as Month,
Mar as value
from yourtable    

Solution 2:

@vkp got me started in the right direction, but I had to add a few tweaks to get it working on Hive:

CREATE TABLE myDatabase.newTable STORED AS TEXTFILE AS 
SELECT item, year, 'jan' AS Month, jan AS Value FROM myDatabase.myTable UNION ALL
SELECT item, year, 'feb' AS Month, feb AS Value FROM myDatabase.myTable UNION ALL
SELECT item, year, 'mar' AS Month, mar AS Value FROM myDatabase.myTable;

Still interested in a solution that works on Pig.


Post a Comment for "Manipulating A Data Structure In Pig/Hive"