我有Hive表,其原始数据类型如下:
CustomerName|City|Product1|RatingByMe|RatingByOthers|Product2|RatingByMe|RatingByOthers
我希望将它转换为复杂的数据类型,包含2个产品的2个单独行并具有此模式:
CustomerName|City|Product1|struct[RatingByMe,RatingByOthers]
CustomerName|City|Product2|struct[RatingByMe,RatingByOthers]
如何在Hive中实现这一目标?任何线索都会受到赞赏。
答案 0 :(得分:2)
您只需使用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
和ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION