Converting columns to rows (UNPIVOT) in hiveql

后端 未结 1 604
孤街浪徒
孤街浪徒 2021-01-14 13:40

I have a table with a structure like this:

column1, column2, column3, X1, X2, X3, X4
A1,      A2,      A3,      5,  6,  1,  4

I would like

1条回答
  •  爱一瞬间的悲伤
    2021-01-14 13:51

    Whoops, posted this in a hurry it seems. I have the answer. Posting it here for others who might find this useful. Here is the correct syntax to deal with map and explode to achieve this.

    select column1, column2, column3, m_key, m_val from
        (select column1, column2, column3, map("X1", X1, "X2", X2, "X3", X3, "X4", X4) as map1
        from table1) as t1
    lateral view explode(map1) xyz as m_key, m_val    
    

    0 讨论(0)
提交回复
热议问题