how to do Transpose in corresponding few columns in pig/hive

后端 未结 2 438
囚心锁ツ
囚心锁ツ 2021-01-19 04:10

I was wondering is it possible to do transposition corresponding few columns in pig/hive.
as dealing with data i got below requirement

id      jan           


        
2条回答
  •  无人共我
    2021-01-19 04:35

    Yes this is definitely possible in Hive using the built-in "stack" UDF and a case statement. Something like this should work:

    select id, value, CASE
    WHEN value like 'j%'
    THEN 'jan'
    WHEN value like 'f%'
    THEN 'feb'
    WHEN value like 'm%'
    THEN 'march'
    ELSE ''
    END as month
    from table
    lateral view stack(3, jan, feb, march) tb as value
    ;
    

    Let me know if this works.

提交回复
热议问题