【问题标题】:LATERAL VIEW EXPLODE in presto横向视图快速爆炸
【发布时间】:2018-12-21 04:35:20
【问题描述】:

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-services hive cloud presto trino


    【解决方案1】:

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

    Trino [原 PrestoSQL] 支持 UNNEST 扩展数组和映射。使用UNNEST 而不是LATERAL VIEW explode()

    Hive 查询:

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

    Presto 查询:

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

    【讨论】:

    • 效果很好!在CROSS JOIN UNNEST(scores) AS t (score); 中,t 是什么意思?
    • @MattFenwick tCROSS JOIN UNNEST(scores) 隐式创建的表的别名。因此,您可以在SELECT 语句中将score 称为t.score
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2018-01-02
      • 2022-08-23
      相关资源
      最近更新 更多