I need to exclude a few selector tags in the dbt run, instead to excluding models which are more in number compared to tags.
I am running
dbt run --fail-fast --profiles-dir . --exclude tag:selector1,tag:selector2,tag:selector3
getting error:
The selection criterion '[tag:selector1,tag:selector2,tag:selector3]' does not match any nodes
my selector entry looks like:
selectors:
- name: selector1
definition:
union:
- intersection:
- method: tag
value: selector1
selectors and tags are two different things. There is no such thing as a "selector tag." It's hard for me to understand exactly what you're trying to do, but to explain the building blocks:
tags are configs that can be applied to any dbt resource (e.g., models, seeds, tests). I can add a tag to a model like this:
-- my_model.sql
{{ config(tags=['tag1', 'tag2']) }}
select 1
I can then run this model (and all other models with tag1
) with:
dbt run -s tag:tag1
I can run all models tagged with either tag1
or tag2
by using union syntax (a space):
dbt run -s tag:tag1 tag:tag2
Or I can run only the models tagged with both tag1
and tag2
by using intersection syntax (a comma):
dbt run -s tag:tag1,tag:tag2
If this gets too complicated, instead of typing in this selection syntax every time at the command line, I can define a custom selector in a .yml file, and reference that selector in my CLI command.
Here's a yml selector for either tag1
or tag2
(union):
selectors:
- name: union_tag1_tag2
description: *either* `tag1` *or* `tag2`
definition:
union:
- method: tag
value: tag1
- method: tag
value: tag2
I would then use this selector at the command line like this:
dbt run --selector union_tag1_tag2
And again, for my second example above, for just models with both tag1
and tag2
(intersection):
selectors:
- name: intersection_tag1_tag2
description: *both* `tag1` and `tag2`
definition:
intersection:
- method: tag
value: tag1
- method: tag
value: tag2
Then I use the new name at the command line:
dbt run --selector intersection_tag1_tag2
I can use --exclude
with tag:
dbt run --exclude tag:tag1
But I can't use --exclude
with a selector. Instead, I define a selector that does the excluding:
selectors:
- name: exclude_intersection_tag1_tag2
description: run all models except those tagged with *both* `tag1` and `tag2`
definition:
exclude:
intersection:
- method: tag
value: tag1
- method: tag
value: tag2
Then I run it with:
dbt run --selector exclude_intersection_tag1_tag2