【问题标题】:dbt relationship test compilation error: test definition dictionary must have exactly one keydbt 关系测试编译错误:测试定义字典必须只有一个键
【发布时间】:2021-10-25 18:32:08
【问题描述】:

我是dbt的新用户,正在尝试写一个关系测试:

- name: PROTOCOL_ID
  tests:
    - relationships:
    to: ref('Animal_Protocols')
    field: id

我收到此错误:

Compilation Error
Invalid test config given in models/Animal_Protocols/schema.yml:
test definition dictionary must have exactly one key, got [('relationships', None), ('to', "ref('Animal_Protocols')"), ('field', 'id')] instead (3 keys)
@: UnparsedNodeUpdate(original_file_path='model...ne)

同一文件中的“unique”和“not-null”测试工作正常,但“accepted_values”出现类似错误。

我在 MacOS Big Sur 11.6 上使用带有 Snowflake 的 dbt cli 版本 0.21.0。

【问题讨论】:

    标签: dbt


    【解决方案1】:

    你很亲密!我 96% 确定这是一个缩进问题——使用 YAML 的第一痛点。解决方案是tofield 都需要在relationships 键下方缩进,而不是在同一级别。

    查看Tests dbt docs page 示例

      - name: PROTOCOL_ID
        tests:
          - relationships:
              to: ref('Animal_Protocols')
              field: id
    

    【讨论】:

    • 谢谢!这是一个很好的线索,虽然它不是确切的问题。我原来的帖子没有显示我的缩进。我的编辑器在每个级别设置了 2 个缩进空间。这适用于大多数级别(例如“-tests:”),但不适用于“-relationships:”下面的级别。一旦我将“to:”和“from:”从 2 个缩进空格更改为 4 个空格,它就起作用了。啊啊啊啊啊啊啊啊!我一直都知道 YAML 的语法是个坏主意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 2015-12-02
    • 1970-01-01
    • 2022-12-11
    • 2021-03-04
    • 1970-01-01
    • 2017-02-25
    相关资源
    最近更新 更多