Skip to content

Groups

新功能

这是v1.5版本的新功能

关于Groups

group是dbt项目中的资源集合。group是命名的,每个group都有一个owner所有者。它们通过限制访问私有模型,实现团队内部和团队之间的有意协作。

声明一个group

Group是一个.yml文件,嵌套在groups: key下

#models/marts/finance/finance.yml
groups:
  - name: finance
    owner:
      # 'name' or 'email' is required; additional properties allowed
      email: finance@jaffleshop.com
      slack: finance-data
      github: finance-data-team

添加模型到group

要将模型添加到group中,请将group属性添加到.yml文件中的模型条目中。

#models/schema.yml
models:
  - name: model_name
    group: finance

引用group中的模型

默认情况下,group中的所有模型在访问中都是受保护的,这意味着它们可以被项目中 任何 group中的下游资源使用ref函数引用。如果分组模型的access属性设置为private,则只有其group中的资源才能引用它。

#models/schema.yml
models:
  - name: finance_model
    access: private
    group: finance
  - name: marketing_model
    group: marketing

#models/marketing_model.sql
select * from {{ ref('finance_model') }}

$ dbt run -s marketing_model
...
dbt.exceptions.DbtReferenceError: Parsing Error
  Node model.jaffle_shop.marketing_model attempted to reference node model.jaffle_shop.finance_model, 
  which is not allowed because the referenced node is private to the finance group.