首页 > 解决方案 > 横向视图快速爆炸

问题描述

presto 的新手,任何指针我如何在 presto 中使用 LATERAL VIEW EXPLODE 用于下表。

我需要在我的 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}}

标签: amazon-web-serviceshivecloudprestotrino

解决方案


来自文档:https ://trino.io/docs/current/appendix/from-hive.html

Trino [原 PrestoSQL] 支持UNNEST扩展数组和映射。使用UNNEST而不是LATERAL VIEW 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);

推荐阅读