From where does DBT (BigQuery) take project and dataset while running the model.

The problem I’m having

When running a model in the dbt cloud, which is connected to BigQuery, from where does it take the project name and dataset name.

I have set the default dataset in the credentials and the dbt_project.yml file and now instead of overriding it joins both dataset names using _. Why is this and how to override it?

yml:

The context of why I’m trying to do this

In some cases, I need to create a model that should ingest in the table in some other database. There are multiple tables like this but the default dataset is only one.

What I’ve already tried

Added the dataset in yml.

Some example code or error messages

added following code in yml

models:
  jaffle_shop:
    dataset: "WORKDB"

Can someone please help.

It is joining both dataset names using _ because this is the default behavior when you have a default and a custom schema

If you want to override it, you have to create your own generate_schema_name macro

So instead of using the default one:

{% macro generate_schema_name(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if custom_schema_name is none -%}

        {{ default_schema }}

    {%- else -%}

        {{ default_schema }}_{{ custom_schema_name | trim }}

    {%- endif -%}

{%- endmacro %}

You can make your own macro inside macros/ folder like

{% macro generate_schema_name(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if custom_schema_name is none -%}

        {{ default_schema }}

    {%- else -%}

        {{ custom_schema_name | trim }}

    {%- endif -%}

{%- endmacro %}

However just know that it is not a good practice, because different developers can override each other schemas this way

The idea behind joining the default and custom schemas with _ is to each developer to work in their own schema

Thanks, @brunoszdl. This is really helpful

HI @kedar.k! If the solution works for you, I would appreciate if you could mark the answer as solution :grin:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.