如何使 dbt 中的增量加载每次运行时都只更新上次运行时的新行?
{% if is_incremental() %}
/* code */
{% endif %}
Run Code Online (Sandbox Code Playgroud)
用于执行此操作的两个主要资源已包含在 dbt 文档中:
如何在 dbt 中构建增量模型: https://docs.getdbt.com/docs/building-a-dbt-project/building-models/configuring-incremental-models/
bigquery 特有的增量模型: https://docs.getdbt.com/reference/resource-configs/bigquery-configs/#merge-behavior-incremental-models
该模型很可能看起来像这样:
{{
config(
materialized='incremental'
)
}}
select <columns>
from <my_table>
{% if is_incremental() %}
where <my_table>.<record_update_timestamp> >= (
select max(<my_table>.<record_update_timestamp>) from {{ this }}
)
{% endif %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6885 次 |
| 最近记录: |