Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

Macro for custom schema names doesn't apply in a dbt package

I have an issue using custom schema names in a dbt package.

I use the Macro provided in dbt documentation.

{% 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 %}

I put this macro in my dbt package here dbt package.

Finally I use this dbt package in another dbt project dbt project.

Here is my dbt_project.yml in my dbt project :

name: 'covid_france'
version: '0.0.1'
config-version: 2

profile: 'default'

source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"  
clean-targets:         
    - "target"
    - "dbt_modules"

My dbt_project.yml in my dbt package :

name: 'covid_france'
version: '0.0.1'
config-version: 2

profile: 'default'

source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target"  
clean-targets:         
    - "target"
    - "dbt_modules"

models:
    covid_france:
        stg:
            materialized: table
            schema: stg
        ods:
            materialized: table
            process-airbyte-outputs:
                schema: ods
            unions:
                schema: ods
        prs:
            materialized: view
      

When I try to run my dbt project, it imports the dbt package but doesn't apply the macro that is supposed to remove the main schema prefix (provided in profiles.yml) from custom schema names For instance : the schema provided in my profiles.yml is "prs". I have other custom schemas named ods and stg. But when dbt run, it create prs, prs_ods and prs_stg.

The macro used to work fine when I use it directly in a dbt project (instead of putting it in a dbt package that I use in my dbt project)

Thank you in advance !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...