Custom target Dataset creation in GBQ using DBT.

The problem I’m having

We have 3 environments, i.e., Landing, Staging, and Data Mart. Tables from different sources will be loaded in the Landing dataset, and we have a view in the same(Landing) layer to get the incremental data as source and table in the Staging dataset as target. Again, View in the Staging layer is used as source and DIM/FACT tables as target in the Data Mart Dataset.

However, when we give the location of the target schema in the STAGING model, it creates the table in the default schema that we provided in the Credentials.

The context of why I’m trying to do this

The requirement mentioned above is working with Snowflake, but we have to migrate to the GBQ.

What I’ve already tried

We followed the steps mentioned in the link below:

Some example code or error messages

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

    {%- set default_schema = target.schema -%}
    {%- if target.name == 'DBT_PROD' and custom_schema_name is not none -%}

        {{ custom_schema_name | trim }}

    {%- else -%}

        {{ default_schema }}

    {%- endif -%}

{%- endmacro %}