dbt tags are another way to select
particular models that you want to run for example down here in your run command
you can select certain models by tag you can select seed snapshots and you can even run tests
like many other things you can set your tags as a model config either in your dbt project or on the
model specific level in the config block so let's go through these examples one at a time
so here we are back in visual studio code looking at our dbt project and what we're going to do is
first set that value in our dbt project file as a model config here when we set this what this
will do is pass through to any model that fits that directory layer for example let's say we
want just for this example directory everything in here to be given a specific tag what we can
do here is let's add another layer for example so this is saying we're going to add configurations
for this directory and within here we'll use the plus sign to indicate that this is a configuration
and the configuration name is tags and the name of the tag will give in this case let's just say
p1 priority one and the way we can run this now to select this would be dbt run use the dash
m for model selection and this time instead of maybe putting one specific model name or a couple
what you can do is say tag colon and then the name of it so we'll go p1 notice that here it's called
tags plural and here you're saying reference this one tag let's go ahead and run this and
we would expect these four example models to run and there it finished and we can see it did run
all four models staging example example example so that covered all of these
now we only have one specific tag here but what you could do is put this on another layer indent
with a dash and make this a list so maybe you want multiple tags so you could add more than
one let's say another tag and if we were to do the same thing and run another tag
we would get the same outcome because now each model has been tagged with both of these and
this would fit this selection and here we can see this ran successfully and you can see now
that you can add one two three however many you want number of tags to any given configuration
so let's say you had some models that you either want to override or maybe you just want to give a
few models here and there a specific tag you can set this in the config block within a model so
if you remember from other videos it's just config and then in here we could say
the attribute is tags and here instead of the colon it'll be equals and it'll be a list
and one we'll give is let's just say special special tag now let's just try to run
tag special and we would expect this time to only run this particular model we would only
expect one not all four and here we can see one of one it's running teams example and that's it
now another interesting way that you could use tags outside of running models is also
with testing models you could go into any of these let's go to our schema here and
you can add a tag in a couple different places let's actually take a quick peek
at the definition here if you go to this tag property so if we go back to the documentation
we can see there's different ways to use tags within models sources seeds snapshots etc
for this video we're just focused on models and if you scroll down you can see there are ways to test
using a tag in this case they're doing pii they've given it to this column and it's going to test
every model with that tag so let's try that if we go back in our project here and let's say we want
our let's let's do the second one why not if we want to say add a another section here called tags
let's say test tag now this tag is associated with this column in this model if you want
to run the test command and just these you would do dbt test dash m for model selection
and tag test tag it would only test this column in this model and this column has two tests so we
should see two tests run let's see what happens here we can see one of two it's running those
two tests on my second model and there you have it it's picking this up and running those tests
the last thing i'll show you is kind of a bonus here i want to show you how you can
actually exclude running some things just by using tags so let's say we wanted to run
everything in the example directory but but not the teams one so we want these three but not teams
the way we could do that is dbt run dash m tag and we can you know we can pick either of these
so let's just do p1 and then dash dash exclude and this might be something new and this is a way to
determine which resources you want and we're going to exclude tag special so we would expect
it to try to run everything but it's going to also identify that this has a tag of special
and not included so we would only see three three of the four here and let's see here one of three
so that's a good sign and we would not see example underscore teams we see team details first model
second model so that worked exactly as expected hopefully this gave you a good insight on how
tags work and you can start to see how it can be a really powerful way to determine which
resources and which models you want to run or test within your project thanks for watching