dbt on_configuration_change 简单说明

dbt on_configuration_change 目前主要是在处理物化视图中,on_configuration_change 包含了三类设置

参考设置

  • apply
    是默认参数,尝试进行更新存在的数据库对象
  • continue
    允许继续运行,但是提供一个警告
  • fail
    如果捕捉到变动就失败

参考使用

  • 比如模型上的
{{ config(
    materialized="<materialization_name>",
    on_configuration_change="apply" | "continue" | "fail"
) }}

materialized_view 实现中的处理

{% macro materialized_view_get_build_sql(existing_relation, target_relation, backup_relation, intermediate_relation) %}
 
    {% set full_refresh_mode = should_full_refresh() %}
 
    -- determine the scenario we're in: create, full_refresh, alter, refresh data
    {% if existing_relation is none %}
        {% set build_sql = get_create_materialized_view_as_sql(target_relation, sql) %}
    {% elif full_refresh_mode or not existing_relation.is_materialized_view %}
        {% set build_sql = get_replace_sql(existing_relation, target_relation, sql) %}
    {% else %}
 
        -- get config options
        {% set on_configuration_change = config.get('on_configuration_change') %}
        {% set configuration_changes = get_materialized_view_configuration_changes(existing_relation, config) %}
 
        {% if configuration_changes is none %}
            {% set build_sql = refresh_materialized_view(target_relation) %}
 
        {% elif on_configuration_change == 'apply' %}
            {% set build_sql = get_alter_materialized_view_as_sql(target_relation, configuration_changes, sql, existing_relation, backup_relation, intermediate_relation) %}
        {% elif on_configuration_change == 'continue' %}
            {% set build_sql = '' %}
            {{ exceptions.warn("Configuration changes were identified and `on_configuration_change` was set to `continue` for `" ~ target_relation ~ "`") }}
        {% elif on_configuration_change == 'fail' %}
            {{ exceptions.raise_fail_fast_error("Configuration changes were identified and `on_configuration_change` was set to `fail` for `" ~ target_relation ~ "`") }}
 
        {% else %}
            -- this only happens if the user provides a value other than `apply`, 'skip', 'fail'
            {{ exceptions.raise_compiler_error("Unexpected configuration scenario") }}
 
        {% endif %}
 
    {% endif %}
 
    {% do return(build_sql) %}
 
{% endmacro %}

说明

模型变动是比较正常的事情,了解on_configuration_change 的一个使用以及配置是比较有用的

参考资料

dbt/include/global_project/macros/materializations/models/materialized_view.sql
https://docs.getdbt.com/reference/resource-configs/on_configuration_change

posted on   荣锋亮  阅读(14)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-05-08 citus ha 参考部署方案
2022-05-08 citus 一些不错的资料
2022-05-08 关于 citus ha 的一些说明
2022-05-08 citus 11.0 beta 发布
2022-05-08 localstack terraform 的支持
2022-05-08 localstack 应用架构
2022-05-08 localstack 运行参考架构

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示