What Is Group In DBT?

Posted on by By admin, in DBT | 0

A group is a collection of nodes within a dbt DAG. Groups are named, and every group has an owner. They enable intentional collaboration within and across teams by restricting access to private models.

Group members may include models, tests, seeds, snapshots, analyses, and metrics. (Not included: sources and exposures.) Each node may belong to only one group.

Groups are defined in .yml files, nested under a “groups:” key.

Example of group

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

Referencing a model in a group

By default, all models within a group have the protected access modifier. This means they can be referenced by downstream resources in any group in the same project, using the ref function. If a grouped model’s access property is set to private, only resources within its group can reference it.

models/schema.yml
models:
  - name: finance_private_model
    access: private
    config:
      group: finance

  # in a different group!
  - name: marketing_model
    config:
      group: marketing

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

The above code throws an error as the access is restricted to “Private” and the group is accessed outside finance group

Adding a model to a group

Use the group configuration to add one or more models to a group.

Project-level

dbt_project.yml
models:
  marts:
    finance:
      +group: finance

Model-level

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

In-file

models/model_name.sql
{{ config(group = 'finance') }}
select ... (sql code)

We at Helical have more than 10 years of experience in providing solutions and services in the domain of data and have served more than 85+ clients. We are also DBT partners, hence in case if you are looking for certain assistance, consulting, services please do reach out on nikhilesh@Helicaltech.com

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments