使用 SQL 向 BigQuery 中的字段添加描述

add descriptions to fields in BigQuery using SQL

我想为 table 中的每个字段添加说明。我的问题是我们正在使用 dbt,并且此工具会在您每次 运行 作业时重新创建 table 导致描述被删除(如果存在)。我能够控制在最后一个 SELECT 语句中转换字段的数据类型,但我不确定是否可以使用 SQL.

添加描述

我在谷歌上搜索了一段时间,但我看不出是否可以使用 SQL 这种方式添加描述。

我想到了一个解决方法,即创建 table 然后插入,但这在理论上是使用 dbt 的糟糕做法。

谢谢!

您可以通过两种方式插入说明。

使用 schema.yml 文件

{version: 2

models:
  - name: events
    description: This table contains clickstream events from the marketing website

    columns:
      - name: event_id
        description: This is a unique identifier for the event
        tests:
          - unique
          - not_null

      - name: user-id
        quote: true
        description: The user who performed the event
        tests:
          - not_null
}

您还可以在 SQL.

中使用 jinga 模板
{% docs table_events %}

This table contains clickstream events from the marketing website.

The events in this table are recorded by [Snowplow](http://github.com/snowplow/snowplow) and piped into the warehouse on an hourly basis. The following pages of the marketing site are tracked:
 - /
 - /about
 - /team
 - /contact-us

{% enddocs %}

只想post解决方案,以防有人遇到同样的问题。 dbt 没有更新 BQ 本身的描述。然而,他们上个月发布了这个新功能:https://github.com/fishtown-analytics/dbt/releases/tag/v0.17.0

可以照常生成文档,BQ会显示表和列的描述。您只需将以下内容添加到您的 dbt_project.yml 文件中:

+persist_docs:
  relation: true
  columns: true