dbt is_incremental macro 简单说明
is_incremental macro 实际上就是一个判断,以下是实现的简单说明,官方文档也有说明
参考处理
- 逻辑
模型必须存在(数据库中),目的表也存在(数据库中),full-refresh 没有传递,模型配置了materialized='incremental'
- macro 实现
结合上边的逻辑发现是可以对应上的
{% macro is_incremental() %}
{#-- do not run introspective queries in parsing #}
{% if not execute %}
{{ return(False) }}
{% else %}
{% set relation = adapter.get_relation(this.database, this.schema, this.table) %}
{{ return(relation is not none
and relation.type == 'table'
and model.config.materialized == 'incremental'
and not should_full_refresh()) }}
{% endif %}
{% endmacro %}
- 参考使用
{{
config(
materialized='incremental'
)
}}
select
*,
my_slow_function(my_column)
from {{ ref('app_data_events') }}
{% if is_incremental() %}
-- this filter will only be applied on an incremental run
-- (uses >= to include records whose timestamp occurred since the last run of this model)
where event_time >= (select max(event_time) from {{ this }})
{% endif %}
说明
结合源码以及官方文档进行dbt 的学习还是比较方便的
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2023-04-24 tracecompass 基于trace+log 分析系统性能问题的gui 工具
2022-04-24 使用localStorage 的storage event 解决多tab 数据共享问题
2022-04-24 多页签websocket 共享
2021-04-24 cube.js schemaVersion npm 包
2021-04-24 开发一个cube.js schemaVersion 包装
2021-04-24 cube.js 多租户参考设计说明
2020-04-24 sql server prometheus 监控