在Hive中构造复杂数据类型

时间:2018-01-05 07:13:19

标签: hive hiveql

我有Hive表,其原始数据类型如下:

CustomerName|City|Product1|RatingByMe|RatingByOthers|Product2|RatingByMe|RatingByOthers

我希望将它转换为复杂的数据类型,包含2个产品的2个单独行并具有此模式:

CustomerName|City|Product1|struct[RatingByMe,RatingByOthers]
CustomerName|City|Product2|struct[RatingByMe,RatingByOthers]

如何在Hive中实现这一目标?任何线索都会受到赞赏。

1 个答案:

答案 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