hi everyone and welcome back to another dbt video in the last video we went through how to create a source and use it to build a new model in this video i'd like to show you what that underlying sql actually looks like if you look at the model as it is currently written in dbt you have a source here and if you wanted to debug this as it gets more complicated that's not really super helpful so how do you know what that's doing every time dbt runs it's actually compiling the sql and storing it separately
and you can find that information in this target folder here it's not there when you first initialize the project but it will show up once you start to actually run models so let's open this up and if we look at compiled we can see it's broken down here it's compiling our model scripts so we have both these in our example as well as the one that we care about so let's open this up and here you can see let's hide this this is the compiled version and here is the dbt version and you can see
it's using this templating here this ginger template and replacing it with the information that we had put here in our in our yaml file so if you ever needed to understand what is actually happening let's say you have a really long script here with a bunch of cte tables and a lot of custom logic with a lot of jinja functions you can go into the compiled folder find what it is but this is something you could actually copy and paste back into snowflake directly and run it so this is really helpful especially when it comes
to debugging as this gets more advanced and you have sources and references and you know let's say we look at here look back at this example here i don't get too many screens open when we look back here what this is doing this second dbt model is using the ref function and what this means is similar to how a source is referring to the yaml file of a source this is referring to another model that's called my first dbt model which they have named it here again in the last one we saw it was looking
for sources with a certain name when you use this ref function it's looking for models with a certain name and if we go back to the compiled for that one we can see it understands where this is coming from and putting the information in there you know you could run this directly in snowflake see whereas if you were to run you know this this doesn't mean anything to snowflake so that's a little bit about how under the hood dbt is compiling your models and it's using the different yaml files and the different templates to put
it together and hopefully make it easier for you to debug if you ever need to thanks for watching