我在 dbt 包中使用自定义模式名称时遇到问题。
我使用dbt 文档中提供的宏。
{% 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 %}
我把这个宏放在我的 dbt 包中dbt package。
最后我在另一个 dbt project dbt project中使用了这个 dbt 包。
这是我的 dbt 项目中的 dbt_project.yml:
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"
我的 dbt 包中的 dbt_project.yml :
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
当我尝试运行我的 dbt 项目时,它会导入 dbt 包,但不会应用应该从自定义模式名称中删除主模式前缀(在 profiles.yml 中提供)的宏 例如:我的配置文件中提供的模式.yml 是“prs”。我还有其他名为 ods 和 stg 的自定义模式。但是当 dbt 运行时,它会创建 prs、prs_ods 和 prs_stg。
当我直接在 dbt 项目中使用该宏时(而不是将其放入我在 dbt 项目中使用的 dbt 包中),该宏曾经可以正常工作
先感谢您 !