You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在tests_config.yml中为DBT源表编写测试?执行命令无响应

源表测试配置修正方案

你的问题核心是测试配置层级错误:源表(source)的测试需要放在sources配置块下,而非models块——models块仅用于配置dbt自建模型的测试,和你定义的外部源表不匹配,所以执行dbt test --select source:*时找不到可运行的测试。

修正后的tests_config.yml

将测试配置迁移到sources节点下,对应你sources.yml里的源名称和表名:

version: 2

sources:
  - name: external  # 必须与sources.yml中的源name完全一致
    schema: external_table
    tables:
      - name: event  # 对应sources.yml中的event表
        tests: 
          - dbt_utils.unique_combination_of_columns:
              combination_of_columns:
                - Event
                - State
                - financial_week_no
                - financial_year
      - name: mapping_table  # 给mapping_table添加测试的示例,可按需修改
        tests:
          - not_null:
              column_name: id  # 示例:检查id列非空
          - unique:
              column_name: code  # 示例:检查code列唯一

重要注意点

  • 配置中的源名称、表名必须与sources.yml里的定义完全匹配,大小写敏感
  • 执行dbt test --select source:*会运行所有源表的测试,若仅需运行external源的测试,可使用dbt test --select source:external
  • 确保已安装dbt_utils包:在packages.yml中声明该包,执行dbt deps拉取依赖,否则unique_combination_of_columns测试会报错

内容的提问来源于stack exchange,提问作者Skylar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 19:58:16