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'asMonth,
Jan asvaluefrom yourtable
UNIONselect item, year,
'Feb'asMonth,
Feb asvaluefrom yourtable
UNIONselect item, year,
'Mar'asMonth,
Mar asvaluefrom 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:

CREATETABLE myDatabase.newTable STORED AS TEXTFILE ASSELECT item, year, 'jan'ASMonth, jan ASValueFROM myDatabase.myTable UNIONALLSELECT item, year, 'feb'ASMonth, feb ASValueFROM myDatabase.myTable UNIONALLSELECT item, year, 'mar'ASMonth, mar ASValueFROM myDatabase.myTable;

Still interested in a solution that works on Pig.

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