为什么DBT在DBT Run语句中运行未被明确针对的模型?

发布于 2025-01-24 19:10:53 字数 431 浏览 1 评论 0原文

我有一个DBT项目,主要由雪花外部桌子上的视图组成。每种模型视图都会同时使用单独的DBT Run语句触发。

dbt run --models model_for_view_1

我在DBT项目中还有另一个模型,该模型可以实现在使用这些视图的表中。我使用与上述相同的DBT Run语句在气流中的单独DAG中触发此模型。它不使用将其连接到视图的参考文章或源语句。

我最近注意到,每当我构建视图模型时,DBT都会建立该表模型。我认为这是因为DBT推断这是一个引用的模型,但是经过一些实验,我什至将表模型SQL设置为诸如Select 1+1 AS Column1之类的东西,它仍在构建中。我将其放在DBT项目中的其他文件夹中,重命名为文件等。没有欢乐。不知道为什么运行其他模型会导致构建这个无关的模型。与视图模型的唯一连接是它们在数据库中共享相同的架构。是什么触发了要构建的模型?

I have a DBT project that is mostly comprised of models for views over snowflake external tables.Every model view is triggered with a seperate dbt run statement concurrently.

dbt run --models model_for_view_1

I have one other model in the dbt project which materializes to a table that uses these views. I trigger this model in a separate DAG in airflow using the same DBT run statement as above. It uses no ref or source statement that connects it to the views.

I noticed recently that this table model is getting built by DBT whenever I build the view models. I thought it was because DBT was making an inference that this was a referenced model but after some experimentation in which I even set the table model SQL as something like SELECT 1+1 as column1, it was still getting built. I have placed it in a different folder in the dbt project, renamed the file etc. No joy. have no idea why running the other models is causing this unrelated model to be built. The only connection to the view models is that they share the same schema in the database. What is triggering this model to be built?

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

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

发布评论

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

评论(1

浮生未歇 2025-01-31 19:10:53

选择语法可能是挑剔的,因为有很多方法可以选择模型。来自 docs

- 选择标志接受一个或多个参数。每个参数可以是:

之一

  1. 包装名称
  2. 模型名称
  3. 模型目录的完全合格的路径
  4. 选择方法(路径:,tag:,config :, test_type:,test_name:)

(请注意-模型被重命名- 在V0.21中选择,但- Models具有相同的行为),

所以我的猜测是您的model_for_view_1 名称不是唯一的,并且要么与您的项目共享(在这种情况下用作包裹),也可以与其所在的目录共享。

因此,如果您的项目看起来像:

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

dbt run -models-models some_name 将在两个some_name.sqlenose_name.sql中运行代码,因为它选择了称为some_name的目录。

Selection syntax can be finicky, because there are many ways to select the models. From 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:)

(note that --models was renamed --select in v0.21, but --models has the same behavior)

So my guess is that your model_for_view_1 name isn't unique, and is either shared with your project (acting as a package in this case) or the directory that it is in.

So if your project looks like:

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

dbt run --models some_name will run the code in both some_name.sql and another_name.sql, since it is selecting the directory called some_name.

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