18

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}}
4

2 回答 2

46

来自文档: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);
于 2018-07-13T01:44:49.573 回答
-6

我能够在查询下方运行以获取映射数据

select
id
,names['1033']['short'] as srt_nm
from id;
于 2018-07-17T19:11:57.167 回答