tags
- Project file
- Config property
- Config block
dbt_project.yml
models:
<resource-path>:
+tags: <string> | [<string>]
snapshots:
<resource-path>:
+tags: <string> | [<string>]
seeds:
<resource-path>:
+tags: <string> | [<string>]
models/resources.yml
version: 2
models:
- name: model_name
config:
tags: <string> | [<string>]
columns:
- name: column_name
tags: [<string>]
tests:
<test-name>:
config:
tags: <string> | [<string>]
{{ config(
tags="<string>" | ["<string>"]
) }}
Definition
Apply a tag (or list of tags) to a resource.
These tags can be used as part of the resource selection syntax, when running the following commands:
dbt run --select tag:my_tag
dbt seed --select tag:my_tag
dbt snapshot --select tag:my_tag
dbt test --select tag:my_tag
(indirectly runs all tests associated with the models that are tagged)
Examples
Use tags to run parts of your project
Apply tags in your dbt_project.yml
as a single value or a string:
dbt_project.yml
models:
jaffle_shop:
+tags: "contains_pii"
staging:
+tags:
- "hourly"
marts:
+tags:
- "hourly"
- "published"
metrics:
+tags:
- "daily"
- "published"
You can also apply tags to individual resources using a config block:
models/staging/stg_payments.sql
{{ config(
tags=["finance"]
) }}
select ...
Then, run part of your project like so:
# Run all models tagged "daily"
$ dbt run --select tag:daily
# Run all models tagged "daily", except those that are tagged hourly
$ dbt run --select tag:daily --exclude tag:hourly
Apply tags to seeds
dbt_project.yml
seeds:
jaffle_shop:
utm_mappings:
+tags: marketing
dbt_project.yml
seeds:
jaffle_shop:
utm_mappings:
+tags:
- marketing
- hourly
Usage notes
Tags are additive
Tags accumulate hierarchically. The above example would result in:
Model | Tags |
---|---|
models/staging/stg_customers.sql | contains_pii , hourly |
models/staging/stg_payments.sql | contains_pii , hourly , finance |
models/marts/dim_customers.sql | contains_pii , hourly , published |
models/metrics/daily_metrics.sql | contains_pii , daily , published |
Other resource types
Tags can also be applied to sources, exposures, and even specific columns in a resource.
These resources do not yet support the config
property, so you'll need to specify
the tags as a top-level key instead.
models/schema.yml
version: 2
exposures:
- name: my_exposure
tags: ['exposure_tag']
...
sources:
- name: source_name
tags: ['top_level']
tables:
- name: table_name
tags: ['table_level']
columns:
- name: column_name
tags: ['column_level']
tests:
- unique:
tags: ['test_level']
In the example above, the unique
test would be selected by any of these four tags:
$ dbt test --select tag:top_level
$ dbt test --select tag:table_level
$ dbt test --select tag:column_level
$ dbt test --select tag:test_level
0