dbt 无法创建具有相同数据库表示形式的两个资源

Man*_*mar 5 dbt

我这里有一个情况如下:

我的dbt项目中有两个模型

  1. 型号-A
{{ config(
    materialized='ephemeral',
    alias='A_0001',
    schema=var('xxx_yyy_dataset')
) }}
Run Code Online (Sandbox Code Playgroud)
  1. B型
{{ config(
    materialized='ephemeral',
    alias='B_0002',
    schema=var('xxx_yyy_dataset')
) }}
Run Code Online (Sandbox Code Playgroud)

这些正在以增量的形式具体化为相同的模式xxx_yyy_dataset.Table_DDD

{{ config(
    materialized='incremental',
    alias='Table_DDD',
    schema=var('xxx_yyy_dataset')
) }}
SELECT * FROM {{ref('A_0001')}}
UNION ALL
SELECT * FROM {{ref('B_0002')}}
Run Code Online (Sandbox Code Playgroud)

这工作正常,并且正在将记录提取到目标表中。

现在我介绍了另一种模型 - model-C ind different package model-C

{{ config(
    materialized='incremental',
    alias='Table_DDD',
    schema=var('xxx_yyy_dataset')
) }}
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误:

$ dbt compile --profiles-dir=profile --target ide
Running with dbt=0.16.0
Encountered an error:
Compilation Error
  dbt found two resources with the database representation "xxx_yyy_dataset.Table_DDD".
  dbt cannot create two resources with identical database representations. To fix this,
  change the "schema" or "alias" configuration of one of these resources:
  - model.eplus_rnc_dbt_project.conrol_outcome_joined (models/controls/payment/fa-join/conrol_outcome_joined.sql)
  - model.eplus_rnc_dbt_project.dq_control_outcome_joined (models/controls/dq/dq-join/dq_control_outcome_joined.sql)
Run Code Online (Sandbox Code Playgroud)

我已经为自定义宏配置了宏,如下所示:

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


{% macro generate_alias_name(custom_alias_name=none, node=none) -%}
    {%- if custom_alias_name is none -%}
        {{ node.name }}
    {%- else -%}
        {{ custom_alias_name | trim }}
    enter code here
    {%- endif -%}
{%- endmacro %}
Run Code Online (Sandbox Code Playgroud)

Cla*_*oll 4

dbt 正在这里发挥作用!

\n

您有两个模型共享完全相同的配置 \xe2\x80\x94conrol_outcome_joineddq_control_outcome_joined.

\n

这意味着它们都将尝试写入同一个表:xxx_yyy_dataset.Table_DDD

\n

dbt(正确地)在这里抛出错误以避免出现问题。

\n

正如错误消息所示,您应该更新其中一个模型以使用不同的架构或别名,以便它在 BigQuery 项目中表示为单独的表。

\n

  • 啊,那么您从根本上打破了 dbt 的范式——一个模型由数据库中的一个表或视图表示。 (4认同)