在 Hive 中构造复杂数据类型
Constructing complex data type in Hive
我的 Hive table 具有如下原始数据类型:
CustomerName|City|Product1|RatingByMe|RatingByOthers|Product2|RatingByMe|RatingByOthers
我希望将其转换为复杂的数据类型,为 2 种产品使用 2 条单独的行,并具有以下架构:
CustomerName|City|Product1|struct[RatingByMe,RatingByOthers]
CustomerName|City|Product2|struct[RatingByMe,RatingByOthers]
如何在 Hive 中实现这一点?任何线索将不胜感激。
您只需要使用 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
我的 Hive table 具有如下原始数据类型:
CustomerName|City|Product1|RatingByMe|RatingByOthers|Product2|RatingByMe|RatingByOthers
我希望将其转换为复杂的数据类型,为 2 种产品使用 2 条单独的行,并具有以下架构:
CustomerName|City|Product1|struct[RatingByMe,RatingByOthers]
CustomerName|City|Product2|struct[RatingByMe,RatingByOthers]
如何在 Hive 中实现这一点?任何线索将不胜感激。
您只需要使用 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