hello and welcome back to another video on dbt a lot of times when building out a data
warehouse or any database for that matter there's the decision of how do you want to
actually store that information do you want it to be persisted data that's stored as a table
do you want it to be just a view on top of another table in dbt world they offer four
options out of the box for us to make those decisions and they're called materializations
as it says here there are strategies for persisting dbt models in a warehouse
and those four options are table view incremental and ephemeral i'll add a link
to this so that you can go through and dig in a little further in terms of what all of these mean
for the sake of this video what we'll focus on is how do you actually make these changes in
your project and what are the two different ways that you can do it one thing to note is by default
models are materialized as views so going into any project you have to understand that that is
the default setting anything else you have to change the two options here we have adjusting
them in our dbt project file and the other is on an individual model level using this config
macro here so let's go back into visual studio and into our project for me i have two subfolders
here one that holds the example models and another for the sample data that we've been working along
if you've been following along in the other videos if we were to do a dbt run right now
we would expect everything to be materialized as a view not only because it's the default but because
we're also explicitly saying here to do everything in this staging folder as a view so both of these
actually fall under a staging folder as well and if we look at the logs we can see everything
is deployed as a view if we look in our data warehouse as well we can see everything here
has been stored as a view now how can we change this let's say that we want to have everything in
this example folder materialize as a table instead of a view the one way we could do that is to add
a new layer here and give the name of the folder which would be example tab in and add this same
clause here but instead change it to table so now this is saying look at staging
example and everything in here should be materialized as a table
instead of a view so let's run this again
we would expect to see two tables and one view
okay table table view
and when we look back in snowflake now we see that they have the two new tables and the view
so that worked as we expected changing it in the dbt project i think is the easiest way to do this
especially if you're organizing your folder structure in a way that matches what your actual
warehouse design looks like you can just you know pick and choose the materialization that you want
the other option here let's say we want to get rid of this here is to use that config macro here
and do it on an individual model level so let's let's copy this part here
and go into one specific model let's just say this one
and at the very top we would paste this in here close out that template
config materialize table you could do this as a view you could do as incremental just as
you would in the project but instead what we're saying here now is only for this specific model
will this take place maybe there's a scenario where you want everything except one or two models
to be a view this is a way you could do that so if we run this again we would expect one table
and two views but we have an error what is this expected oh i forgot to close out this here
config that has to close out try it again so to review everything in this staging
directory here would be a view except for when it gets to this model it's going to be overridden by
this function here and we can see the one table for the first model which is this one
if we refresh that's what we see so that's a little bit about how the materializations
work in dbt i hope you found this helpful and thank you for watching