【问题标题】:DBT 'dbt snapshot' command resulting in error: "Database Error in snapshot snapshot_name Unrecognized name: id at [53:13]"DBT 'dbt snapshot' 命令导致错误:“快照快照名称中的数据库错误无法识别名称:id at [53:13]”
【发布时间】:2021-05-21 14:36:29
【问题描述】:

正如问题所说,我正在运行 dbt snapshot 命令,但我的一些快照无法正常工作,因为 DBT 无法识别我创建的代理键 id。我的快照都是以相同的方式构建的,它们所基于的基本视图也是如此。以下是由于无法识别代理键而无法工作的快照示例:

{% snapshot example_snapshot %}
    {{ config(
        target_schema = 'snapshots',
        unique_key = 'id',
        strategy = 'check',
        check_cols = 'all'
    ) }}

    SELECT
        *
    FROM
        {{ ref('base_example') }}
{% endsnapshot %}

后面是它所引用的基本视图的示例:

WITH src AS (
    SELECT
        *
    FROM
        {{ source(
            'tomato',
            'potato'
        ) }}
),
cleaned AS (
    SELECT
        *,
        {{ dbt_utils.surrogate_key(['column', 'another_column', 'yet_another_column']) }} AS id
    FROM
        src
)
SELECT 
    *
FROM 
    cleaned

请记住,当我运行命令 dbt run -m [base_example] 时,它会生成一个视图,在该视图中我可以看到作为代理键生成的哈希值。只有当我运行dbt snapshot 时才会出现问题。事实上,运行dbt snapshot --select [example_snapshot] 一次只运行一个快照不会给我任何快照的任何错误。最令人困惑的部分:我有一个基本视图和该基本视图的快照,完全配置为其他 3 个不起作用,但它在创建快照时识别代理键。我真的很难过,任何帮助将不胜感激。

【问题讨论】:

    标签: sql snapshot dbt surrogate-key


    【解决方案1】:

    根据我的经验,当依赖于 dbt 模型(通过ref('base_example'))而不是源时,快照可能会有点不稳定。这是可取的,尽管文档中没有详细解释为什么to select from the source

    由于您的转换只是基于源中的三列添加代理键,我想知道您是否可以将转换粘贴在 unique_key 参数中,á la(这里在 Redshift 领域思考,未经测试):

    {% snapshot example_snapshot %}
        {{ config(
            target_schema = 'snapshots',
            unique_key = 'md5(column, another_column, yet_another_column)',
            strategy = 'check',
            check_cols = 'all'
        ) }}
    
        SELECT
            *
        FROM
            {{ source('tomato', 'potato') }}
    {% endsnapshot %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 2022-12-22
      • 2021-12-31
      • 2022-07-22
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多