My current table is as below
username col1 col2 col3
x 1 2 3
y 4 5 6
z 7 8 9
I have several table like this but the number of columns may be different. (example: another table have columns username,col1,col2,col3,col4,col5)
I want to collapse all the columns to single column and introduce the new column to store column names
So now my new tables look like this
username col_new val
x col1 1
x col1 2
x col1 3
y col2 4
y col2 5
y col2 6
z col3 7
z col3 8
z col3 9
I can do it manually. But since the number columns are different in each table, So want a hive query which can take variable number of columns and create the above table like format.
Please suggest.