0

My wide data look like this:

enter image description here

What I am trying to accomplish is long:

enter image description here

I have many Score_X's and each score has many items. So the less hard-coding (e.g. Convert data from wide format to long format in SQL) the better.

I have thought about a few ways to do this; unfortunately Hive does not have many features that other SQL implementations have. So first I would appreciate a solution to my problem, and secondly, if anyone knows easy ways to emulate these things in Hive please do share with me.

  1. The pivot function, which Hive doesn't have.
  2. I tried to apply Joe Stefanelli's answer in Selecting all columns that start with XXX using a wildcard?. Hive does not have INFORMATION_SCHEMA either. I was told (also by stackoverflow) that I could get table metadata by first installing MySQL and then detour through MySQL; I don't feel like spending that much effort on a simple task like reshaping a table...
  3. Then I think I can combine the values of Score_A_1, Score_A_2 and Score_A_3 into one Score_A array and then do a LATERAL VIEW EXPLODE like in myui's answer in How to transpose/pivot data in hive?. But I Googled around and could not find a tutorial to do that.

Thanks. Your help is greatly appreciated.

Update: So the array function will create an array column from multiple columns. Now I am doing the LATERAL VIEW EXPLODE; through hard-coding (i.e., non-dynamic query) I am getting what I want. However it is difficult to believe that there is not a simpler way to perform a data management task as basic as reshaping. Am I missing something fundamental about Hive?

Community
  • 1
  • 1
Alex
  • 33
  • 8
  • Possible duplicate of [Hive - Unpivot functionality in hive](http://stackoverflow.com/questions/32621970/hive-unpivot-functionality-in-hive) – o-90 Aug 06 '16 at 01:18
  • https://www.quora.com/Is-there-a-way-to-transpose-data-in-Hive/answer/John-Martinez-41 – o-90 Aug 06 '16 at 01:19

0 Answers0