in this video we're going to look at the jinja function of invocation id and invocation id is
something that you can use anywhere within the context of your dbt run and as it says
here it's very useful for auditing and analyzing dvt invocation metadata and in my mind a really
good use case for this like it says is auditing or for tracking things that are associated with a
specific run so what we'll do here is look at how you can use it and what that ultimately looks like
if you're not familiar with uuids it stands for universally unique identifier and it will look
something like this it'll be a mix of numbers letters and a couple dashes in between and every
single time you run this it's going to create a brand new one of these which based on the way
this works it will always be a unique value so you'll never get the same number twice any time
you run it so the question is how can we use this in dbt and considering it's a jinja function we'll
reference it very similar to how we would a function or variable anything like that
let's go ahead and jump into one of these example models here this one's very simple it's just a
bunch of unions of some nba teams here and what we'll do is add a new column for this invocation
id and what we'll do is we'll put this as a string and put it as a function two curly brackets
invocation id
close out the brackets and we'll give it a name so the first thing i want to show you
is what this looks like when we compile it so we'll do dbt compile and the reason i want to
do this is to show you what this value will look like so let's go to our target compiled
and here we can see this value so this was the unique identifier that was created for
that particular run or compilation of dbt now if we do this again we're going to see this change
and there it did it just changed so now we can see this is what it will look like
anytime we run this model it's always going to change and what's going to happen is anywhere
that you use this value within the context of a run it will have the same invocation id
across the board so it's very easy to tie things back together to a specific run because you know
they'll all have that unique value so let's just do a dbt run model example teams to see what this
looks like in snowflake just to prove the point okay so this finished we'll go into snowflake
i'll refresh and if we go to this table here we now have invocation id and so we can see these
all have the same invocation id as expected let's add this to another model to show that it will be
the same across the board so i'm going to add it to this one team details we'll add the same column
invocation id and let's run both of them what we would expect here is for both tables to have this
column and they would be the exact same value in this case they'll be the exact same because it's
going to be materializing both as a table so it'll be brand new records but let's take a look so team
details let's preview again here's the value i'll copy this for the so that we can see it
and if we look at team details this now has that column and this also all have the same value
so anywhere you use this in the context of that run whether it's two models one model 100 models
anything in the context of that run if you use that invocation id will get the same value
so again a good use case for this is for auditing you can track you know which invocation id where
records were updated inserted or whatnot and then tie it back to perhaps an audit table using this
method and as you do incremental loads you can you'll see that will become even more valuable
so i hope you found this helpful and please let me know if there are any questions on how
this works or places to use it