有没有办法指定DBT中模型中所有测试的任何条件?
我想为我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何可以在
dbt_project.yml
中应用的配置都可以示范到特定目录或资源。但是,测试是他们自己的资源,独立于他们测试的模型,而当前(DBT V1.2),不可能将配置应用于给定模型的所有测试。作为解决方法,您可以考虑放置
.yml
文件,该文件本身会在目录中定义该模型的测试,并将配置应用于目录。应用在整个项目中应用:
应用仅在
.yml
文件中嵌套在models/marts/finance/finance/code中>目录:
应用
在其中
对特定测试:请参阅资源路径有关更多信息
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:Apply
where
only to.yml
files nested in themodels/marts/finance/
directory:Apply
where
to a specific test:See the docs for resource-path for more info