有没有办法指定DBT中模型中所有测试的任何条件?

发布于 2025-02-04 05:30:49 字数 423 浏览 3 评论 0原文

我想为我的DBT模型编写一些测试。我只希望测试测试某些行(上个月内的数据)。我可以在yml文件中的每个测试中编写一个条款,

          - not_null
          config:
            where: "current_date-date_column<=30"

但是,我想知道是否有一些捷径可以将子句放在模型上,并且在其中的所有测试中都适用于模型的所有测试(这很多(这是很多)更容易编写,这也意味着我不必担心是否添加更多测试)。

本文希望整个项目只有一个模型。

I would like to write some tests for my dbt model. I only want the tests to test certain rows (data within the last month). I could write a where clause for every single test in yml file like so:

          - not_null
          config:
            where: "current_date-date_column<=30"

However, I was wondering if there is some shortcut to put the clause on the model and have the where clause apply to all tests of the model (which is a lot easier to write and also means I don't have to worry about forgetting if I add more tests).

This article givers an example on how to do that for project level but I don't want the whole project just one model.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2025-02-11 05:30:49

任何可以在dbt_project.yml中应用的配置都可以示范到特定目录或资源。但是,测试是他们自己的资源,独立于他们测试的模型,而当前(DBT V1.2),不可能将配置应用于给定模型的所有测试。

作为解决方法,您可以考虑放置.yml文件,该文件本身会在目录中定义该模型的测试,并将配置应用于目录。

应用在整个项目中应用:

tests:
  +where: "date_column = current_date"

应用仅在.yml文件中嵌套在models/marts/finance/finance/code中>目录:

tests:
  my_project:
    marts:
      finance:
        +where: "date_column = current_date"

应用在其中对特定测试:

tests:
  my_project:
    marts:
      finance:
        not_null_revenue_id:
          +where: "date_column = current_date"

请参阅资源路径有关更多信息

Any config that can be applied in the dbt_project.yml can be scoped to specific directories or resources. However, tests are their own resources, independent of the models they test, and currently (dbt v1.2), it is not possible apply config to all tests for a given model.

As a workaround, you could consider putting the .yml file that defines the tests for that model in a directory by itself, and applying the config to a directory.

Apply where to a whole project:

tests:
  +where: "date_column = current_date"

Apply where only to .yml files nested in the models/marts/finance/ directory:

tests:
  my_project:
    marts:
      finance:
        +where: "date_column = current_date"

Apply where to a specific test:

tests:
  my_project:
    marts:
      finance:
        not_null_revenue_id:
          +where: "date_column = current_date"

See the docs for resource-path for more info

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文