为什么 DBT 运行ning 模型未在 DBT 运行 声明中明确定位?

Why is DBT running a model that is not being targeted explicitly in the DBT run statement?

我有一个 DBT 项目,主要由用于查看雪花外部视图的模型组成 tables.Every 模型视图同时由单独的 dbt 运行 语句触发。

dbt run --models model_for_view_1

我在 dbt 项目中有另一个模型,它具体化为使用这些视图的 table。我使用与上面相同的 DBT 运行 语句在气流中的单独 DAG 中触发此模型。它不使用 ref 或 source 语句将其连接到视图。

我最近注意到,每当我构建视图模型时,DBT 都会构建这个 table 模型。我认为这是因为 DBT 正在推断这是一个参考模型,但经过一些实验后,我什至将 table 模型 SQL 设置为 SELECT 1+1 作为 column1 , 它仍在建造中。我已将它放在 dbt 项目的不同文件夹中,重命名文件等。没有快乐。不知道为什么 运行 使用其他模型会导致构建这个不相关的模型。与视图模型的唯一联系是它们在数据库中共享相同的模式。是什么触发了此模型的构建?

您能否在这里分享更多背景信息。 您的项目使用哪个版本的 dbt? 是否可以分享模型的外观(同时删除任何敏感信息)。

如果没有这些信息,很难判断是什么触发了这种意外行为。

选择语法可能很挑剔,因为 select 模型有很多方法。来自 the docs:

The --select flag accepts one or more arguments. Each argument can be one of:

  1. a package name
  2. a model name
  3. a fully-qualified path to a directory of models
  4. a selection method (path:, tag:, config:, test_type:, test_name:)

(请注意,--models 在 v0.21 中已重命名为 --select,但 --models 具有相同的行为)

所以我的猜测是您的 model_for_view_1 名称不是唯一的,并且与您的项目共享(在这种情况下作为一个包)或它所在的目录(很可能是后者).

因此,如果您的项目如下所示:

models
 |- some_name
    |- some_name.sql  # the view
    |- another_name.sql  # the table

dbt run --models some_name 将 运行 some_name.sqlanother_name.sql 中的代码,因为它是 select 名为 some_name 的目录。