我在Presto查询中有以下查询。想要将其转换为HIVE查询。我找不到与“ CAST(as ARRAY)”等效的Hive,我见过人们使用Hive正则表达式/字符串方法从每个json元素(Parse JSON Array and load into hive table)中提取内容,但是我不确定是否是只有这样,否则Hive也可以像Presto一样整洁。
“ resp”的结构
{
results:[{id:xx, source:xx},{id:xx, source:xx},...]
}
Presto查询
select
cast(json_extract(feed, '$.source') as VARCHAR) as src,
cast(json_extract(feed, '$.id') as VARCHAR) as id
from my_tbl
CROSS JOIN UNNEST (CAST(json_extract(resp, '$.results') AS ARRAY<JSON>)) t (feed)