From df33b0ed60da4f88526981d9074346bb4e735b7d Mon Sep 17 00:00:00 2001 From: mirnawong1 Date: Fri, 10 Jan 2025 12:37:58 +0000 Subject: [PATCH 1/5] add model example --- .../docs/reference/resource-configs/tags.md | 76 ++++++++++++++++--- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/website/docs/reference/resource-configs/tags.md b/website/docs/reference/resource-configs/tags.md index 505a33a00f7..aa55ba89efe 100644 --- a/website/docs/reference/resource-configs/tags.md +++ b/website/docs/reference/resource-configs/tags.md @@ -93,6 +93,21 @@ resource_type: ``` + +For example, to apply tags to a model in your `models/` directory, you would add the following using the `config` property: + + + +```yaml +models: + - name: my_model + description: A model description + config: + tags: ['example_tag'] +``` + + + @@ -126,10 +141,22 @@ You can use the [`+` operator](/reference/node-selection/graph-operators#the-plu - `dbt run --select +model_name+` — Run a model, its upstream dependencies, and its downstream dependencies. - `dbt run --select tag:my_tag+ --exclude tag:exclude_tag` — Run model tagged with `my_tag` and their downstream dependencies, and exclude models tagged with `exclude_tag`, regardless of their dependencies. + +:::tip Usage notes about tags + +- Tags are additive across project hierarchy. +- Some resource types (like sources, exposures) require tags at the top level. + +Refer to [usage notes](#usage-notes) for more information. +::: + ## Examples + +The following examples show how to apply tags to resources in your project. You can configure tags in the `dbt_project.yml`, `schema.yml`, or SQL files. + ### Use tags to run parts of your project -Apply tags in your `dbt_project.yml` as a single value or a string: +Apply tags in your `dbt_project.yml` as a single value or a string. In the following example, one of the models, the `jaffle_shop` model, is tagged with `contains_pii`. @@ -153,16 +180,52 @@ models: - "published" ``` + + + +### Apply tags to models + +You can also apply tags to individual resources, like models, using in the `dbt_project.yml`, `schema.yml`, or SQL files. + +To apply tags to a model in your `dbt_project.yml` file, you would add the following: + + + +```yaml +models: + jaffle_shop: + +tags: finance # jaffle_shop model is tagged with 'finance'. +``` -You can also apply tags to individual resources using a config block: +To apply tags to a model in your `models/` directory YAML file, you would add the following using the `config` property: + + + +```yaml +models: + - name: stg_customers + description: Customer data with basic cleaning and transformation applied, one row per customer. + config: + tags: ['santi'] # stg_customers.yml model is tagged with 'santi'. + columns: + - name: customer_id + description: The unique key for each customer. + data_tests: + - not_null + - unique +``` + + + +To apply tags to a model in your SQL file, you would add the following: ```sql {{ config( - tags=["finance"] + tags=["finance"] # stg_payments.sql model is tagged with 'finance'. ) }} select ... @@ -211,14 +274,10 @@ seeds: -:::tip Upgrade to dbt Core 1.9 - -Applying tags to saved queries is only available in dbt Core versions 1.9 and later. -::: + - This following example shows how to apply a tag to a saved query in the `dbt_project.yml` file. The saved query is then tagged with `order_metrics`. @@ -263,7 +322,6 @@ Run resources with multiple tags using the following commands: # Run all resources tagged "order_metrics" and "hourly" dbt build --select tag:order_metrics tag:hourly ``` - ## Usage notes From ff2744b94672e68f59aec02953c2997e1423d222 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:44:50 +0000 Subject: [PATCH 2/5] Update website/docs/reference/resource-configs/tags.md --- website/docs/reference/resource-configs/tags.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/resource-configs/tags.md b/website/docs/reference/resource-configs/tags.md index aa55ba89efe..cda0bec58b1 100644 --- a/website/docs/reference/resource-configs/tags.md +++ b/website/docs/reference/resource-configs/tags.md @@ -185,7 +185,7 @@ models: ### Apply tags to models -You can also apply tags to individual resources, like models, using in the `dbt_project.yml`, `schema.yml`, or SQL files. +This section shares how to apply tags to models in the `dbt_project.yml`, `schema.yml`, or SQL files, however you can also apply tags to individual resources. To apply tags to a model in your `dbt_project.yml` file, you would add the following: From e9f4955b4fd9e58b9e971e7458dd97eb440e1143 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:23:35 +0000 Subject: [PATCH 3/5] Update website/docs/reference/resource-configs/tags.md Co-authored-by: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> --- website/docs/reference/resource-configs/tags.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/resource-configs/tags.md b/website/docs/reference/resource-configs/tags.md index cda0bec58b1..a25521d71ab 100644 --- a/website/docs/reference/resource-configs/tags.md +++ b/website/docs/reference/resource-configs/tags.md @@ -94,7 +94,7 @@ resource_type: -For example, to apply tags to a model in your `models/` directory, you would add the following using the `config` property: +To apply tags to a model in your `models/` directory, add the `config` property similar to the following example: From 0cd0fac4a80033e168b110150127cc2a91075b15 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:23:44 +0000 Subject: [PATCH 4/5] Update website/docs/reference/resource-configs/tags.md Co-authored-by: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> --- website/docs/reference/resource-configs/tags.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/reference/resource-configs/tags.md b/website/docs/reference/resource-configs/tags.md index a25521d71ab..547e13ecda4 100644 --- a/website/docs/reference/resource-configs/tags.md +++ b/website/docs/reference/resource-configs/tags.md @@ -144,6 +144,8 @@ You can use the [`+` operator](/reference/node-selection/graph-operators#the-plu :::tip Usage notes about tags +When using tags, consider the following: + - Tags are additive across project hierarchy. - Some resource types (like sources, exposures) require tags at the top level. From 10248cc0ae2115ab38a74fc42fe538da503f7b10 Mon Sep 17 00:00:00 2001 From: Mirna Wong <89008547+mirnawong1@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:24:02 +0000 Subject: [PATCH 5/5] Update website/docs/reference/resource-configs/tags.md Co-authored-by: Matt Shaver <60105315+matthewshaver@users.noreply.github.com> --- website/docs/reference/resource-configs/tags.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/resource-configs/tags.md b/website/docs/reference/resource-configs/tags.md index 547e13ecda4..6fc8960af7c 100644 --- a/website/docs/reference/resource-configs/tags.md +++ b/website/docs/reference/resource-configs/tags.md @@ -187,7 +187,7 @@ models: ### Apply tags to models -This section shares how to apply tags to models in the `dbt_project.yml`, `schema.yml`, or SQL files, however you can also apply tags to individual resources. +This section demonstrates applying tags to models in the `dbt_project.yml`, `schema.yml`, and SQL files. To apply tags to a model in your `dbt_project.yml` file, you would add the following: