dbt:访问源 schema.yml 中指定的源列的测试 示例源 schema.yml

问题描述

列级架构测试在图中的哪个位置?

我之所以这么问,是因为我想根据列的 not_null 测试的存在,在 CREATE TABLE 语句中设置列的可空性。

例如,我如何确定下面 customers 表中的列是否有 not_null 测试?

我的想法是这样的

{% set source_nodes = graph.sources.values() if graph.sources else [] %}
{% for node in source_nodes %}
    {%- set columns = source_node.columns.values() -%}
    {% for column in columns %}
        {%- set nullity = 'NOT NULL' if 'not_null' in column.tests else 'NULL'-%}

但是列 dict 具有以下属性并且 'test' 不是 column dict 中的键。

{
    'name': 'id','description': 'Primary key of the table','Meta': {},'tags': []
}

测试信息在哪里?!?

示例源 schema.yml

version: 2

sources:
  - name: raw_jaffle_shop
    description: A replica of the postgres database used to power the jaffle_shop app.
    tables:
      - name: customers
        columns:
          - name: id
            description: Primary key of the table
            tests:
              - unique
              - not_null

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)