横向视图在普雷斯托爆炸

webghufk  于 2021-06-26  发布在  Hive
关注(0)|答案(2)|浏览(490)

新的普雷斯托,任何指针如何我可以使用横向视图爆炸普雷斯托为下表。
我需要在presto查询中筛选名字

CREATE EXTERNAL TABLE `id`(
 `id` string,
 `names` map<string,map<string,string>>,
 `tags` map<string,map<string,string>>)
ROW FORMAT SERDE
 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' 
STORED AS INPUTFORMAT
 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' 
OUTPUTFORMAT
 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat'
LOCATION
 's3://test'

;
样品 names 价值:

{3081={short=Abbazia 81427 - Milan}, 2057={short=Abbazia 81427 - Milan}, 1033={short=Abbazia 81427 - Milan}, 4105={short=Abbazia 81427 - Milan}, 5129={short=Abbazia 81427 - Milan}}
0x6upsns

0x6upsns1#

根据文件:https://trino.io/docs/current/migration/from-hive.html
trino(以前叫prestosql)支持unnest来扩展数组和Map。使用unnest而不是侧向视图explode()。
配置单元查询:

SELECT student, score
FROM tests
LATERAL VIEW explode(scores) t AS score;

预查询:

SELECT student, score
FROM tests
CROSS JOIN UNNEST(scores) AS t (score);
m4pnthwp

m4pnthwp2#

我可以运行下面的查询来获取Map的数据

select
id
,names['1033']['short'] as srt_nm
from id;

相关问题