首页 > 其他分享 >dbt on_configuration_change 简单说明

dbt on_configuration_change 简单说明

时间:2024-05-08 12:11:48浏览次数:14  
标签:set materialized relation sql configuration dbt 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

标签:set,materialized,relation,sql,configuration,dbt,change
From: https://www.cnblogs.com/rongfengliang/p/18157247

相关文章

  • 事件处理函数中, e.stopPropagation()能放在 onChangeColor()后边执行吗?
    在JavaScript事件处理中,e.stopPropagation()的作用是阻止事件向上冒泡到父元素,也就是说,它防止当前元素的事件继续传播到DOM树上的其他事件监听器。因此,它的位置对于事件流的行为至关重要。将e.stopPropagation()放在onChangeColor()后面执行,在大多数情况下不会改变onChange......
  • dbt show 命令处理简单说明
    dbtshow主要做以下事情内部处理编译基于sql的model,test,analysis,或者执行基于--inline的sql,当前不支持python模型在dw中执行查询在终端中预览结果备注:默认limit为5,但是可以自己调整通过--limit参数,同时dbtshow使用的一直是最新的数据以及编译模型,不会使用物化的......
  • dbt docs generate 简单说明
    dbtdocsgenerate核心是获取dbt项目的元数据信息(包含了project的)以及相关table的(dbt模型相关的),然后通过提供的解析页面进行显示目前是基于静态处理的(先生成,然后基于纯web的解析渲染)对于展示方法很多,可以基于dbt的docsserve命令也可以基于自己的静态webserver(nginx或......
  • dbt 自定义schema 简单说明
    dbt的schema我们是可以灵活进行自定义的,可以实现一个比较有意思的事情使用场景模型级别的schema自定义seed数据schema自定义不同env或者vars的schema自定义不同targetschema的自定义schema自定义核心是generate_schema_name这个macro,我们可以自己定义参考自......
  • dbt Relation 扩展简单说明
    dbt的Relation实际上就是包含关系数据库表,数据库,schema一些信息的描述,dbt官方提供了api.Relation.create等操作进行Relation的维护,当然系统的builtins也提供了一些基本的操作能力,内部使用上会使用dbtBaseRelation中的各类实现比如pg就自己扩展了一个,同时在自己的m......
  • dbt 自定义AdapterPlugin 中dependencies 简单说明
    结合dbt-redshift的对于dependencies部分的定义以及使用简单说明下参考代码Plugin:AdapterPlugin=AdapterPlugin(adapter=RedshiftAdapter,#type:ignorecredentials=RedshiftCredentials,include_path=redshift.PACKAGE_PATH,dep......
  • dbt dbt-audit-helper 包提供的一些方便macro
    dbt-audit-helper从字面意思是dbt的审计帮助工具,但是实际上我们也可以使用此工具做一些数据质量相关的东西dbt-audit-helper提供的macro比较数据输出包含了compare_relations,compare_queries,compare_row_counts比较列compare_column_values,cmpare_all_columns,com......
  • Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions
    Category:Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareEventId:1RequestId:800000f3-0003-eb00-b63f-84710c7967bbRequestPath:/SampleSpanId:|e04026eb-470f4c64c48ec282.TraceId:e04026eb-470f4c64c48ec282ParentId:Anunhandledexception......
  • A. Card Exchange.
    原题链接题解1.如果一开始没有\(k\)个相同的卡片,答案是\(n\)2.否则将按照如下步骤取\(k\)个相同卡片如果取出卡片后,没有剩余卡片了,随便放\(k-1\)个卡片进去,游戏结束否则把\(k-1\)个卡片全部变成剩余卡片中的一个,情况回到第一个步骤code#include<bits/stdc++.h>......
  • Rabbitmq系列02---Exchange
    个人理解:交换机的类型划分个人理解是能过routingkey来划分的,一是否按routingkey找队列;fanout就是不按routingkey找队列,Direct和Topicr按routingkey找队列,只是一个模糊找,一个精准找,而headers不按routingkey是按消头中的内容找队列。一、Fanout(订阅模式|广播模式)  Fanout......