【问题标题】:Querying S3 inventory details in Athena在 Athena 中查询 S3 库存详细信息
【发布时间】:2019-02-21 15:58:24
【问题描述】:

我在 S3 存储桶中有 S3 库存详细信息,我正在通过 Athena 查询它。

我的前两列如下所示:

bucket                  key
bke-p0d-bke-lca-data    dl/xxxxxx/plant/archive/01-01-2019/1546300856.json
bke-pod-bke-lca-data    dl/xxxx/plant/archive/01-01-2019/1546300856.json
bke-pod-bke-lca-data    dl/xxx/plant/archive/01-01-2019/1546300856.json

我需要他们将关键信息拆分为以下内容:

bucket                  Categ   Type    Date        File
bke-pod-bke-lca-data    xxxxxx  archive 01/01/2019  1546300856.json
bke-pod-bke-lca-data    xxxx    working 01/01/2019  1546300856.json
bke-pod-bke-lca-data    xxx     archive 01/01/2019  1546300856.json

我试过substr 没用。

如何根据/进行拆分?

【问题讨论】:

    标签: amazon-athena presto


    【解决方案1】:

    6.8. String Functions and Operators — Presto 0.172 Documentation 有:

    split_part(string, delimiter, index)delimiter 上拆分string 并返回字段index。字段索引以1 开头。如果索引大于字段数,则返回 null。

    所以,你应该可以使用类似的东西:

    SELECT
      bucket,
      split_part(key, '/', 2) as category,
      split_part(key, '/', 4) as type,
      split_part(key, '/', 5) as date,
      split_part(key, '/', 6) as file
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      • 2012-10-10
      • 2011-05-19
      • 1970-01-01
      相关资源
      最近更新 更多