我有一个包含如下基本数据类型的配置单元表:
CustomerName|City|Product1|RatingByMe|RatingByOthers|Product2|RatingByMe|RatingByOthers
我希望将其转换为复杂的数据类型,其中两个产品有两个单独的行,并且具有以下模式:
CustomerName|City|Product1|struct[RatingByMe,RatingByOthers]
CustomerName|City|Product2|struct[RatingByMe,RatingByOthers]
如何在Hive中实现这一点?任何线索都将不胜感激。
1条答案
按热度按时间n3schb8v1#
你只需要用一个
union
和一个named_struct
```select
CustomerName,
City,
Product1,
named_struct("RatingByMe", RatingByMe, "RatingByOthers", RatingByOthers) as rating
from your_table
union all
select
CustomerName,
City,
Product2,
named_struct("RatingByMe", RatingByMe, "RatingByOthers", RatingByOthers) as rating
from your_table