【问题标题】:Unnesting Multiple Nested Fields Deep in BigQuery在 BigQuery 中取消嵌套多个嵌套字段
【发布时间】:2018-10-25 20:38:02
【问题描述】:

我正在尝试使用 BigQuery 中的标准 SQL 方言来取消嵌套 changelog.histories.items 重复记录(以绿色勾勒)以访问嵌套项目表中的行(以蓝色勾勒)。父记录“更改日志”(以红色标出)不是重复记录,因此我在弄清楚要取消嵌套的内容时遇到问题。

尝试取消嵌套 changelog.histories 或 changelog.histories.items 的查询会导致以下错误。

SELECT changelog.histories.items.to
FROM jirasparta_database.jira_issues, 
     unnest(changelog.histories) 

错误:无法访问类型为 ARRAY,...> 的值的字段项,项 ARRAYto STRING,字段 STRING,字段类型 STRING,...>>,...>> 在 [1:28 ]

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:
    #standardSQL
    SELECT item.to   
    FROM jirasparta_database.jira_issues, 
    UNNEST(changelog.histories) history, UNNEST(history.items) item
    

    基本上,您必须展平 STRUCT 和 ARRAY 值。您可以查看this documentation 了解更多详情。

    【讨论】:

    • 美丽。非常感谢。
    • 感谢您对这个简单而简洁的解释
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 1970-01-01
    相关资源
    最近更新 更多