【发布时间】:2021-06-06 19:41:43
【问题描述】:
我正在尝试在 BigQuery 上使用 dbt 构建增量模型,但我似乎遗漏了有关我的代码或增量模型工作方式的一些细节。
我正在构建我的五个功能键的唯一哈希,它们是 POSStoreCode, StoreSystemType, TargetStartDate, TargetEndDate and TargetSalesType
我的增量模型如下所示。
{{ config(materialized='incremental', alias='Sales_Target_Oblique_v1', schema='bq_ed_harmonized_'+var('env'), unique_key='Checksum') }}
with salestarget as (
select
store_code as POSStoreCode,
store_name as StoreName,
'SID' as StoreSystemType,
target_qty as TargetQuantity,
target_start_date as TargetStartDate,
target_end_date as TargetEndDate,
concat('Women ', ProductCategory) as TargetSalesType,
cast(NULL as float64) as TargetAmount,
'{{ var("transaction_id") }}' as ProcessingId,
CURRENT_DATETIME() as CreationDatetime,
CURRENT_DATETIME() as LastUpdateDatetime
from {{ ref('salestarget') }} ),
harmonized_salestarget as (
select
* ,
{{ dbt_utils.surrogate_key(['POSStoreCode', 'StoreName', 'StoreSystemType', 'TargetQuantity', 'TargetStartDate', 'TargetEndDate', 'TargetSalesType', 'TargetAmount']) }} as Checksum
from salestarget
)
select * from harmonized_salestarget
{% if is_incremental() %}
where Checksum != {{ dbt_utils.surrogate_key(['POSStoreCode', 'StoreName', 'StoreSystemType', 'TargetQuantity', 'TargetStartDate', 'TargetEndDate', 'TargetSalesType', 'TargetAmount']) }}
{% endif %}
当我第一次执行模型时,它通过创建表 Sales_Target_Oblique_v1 并将数据加载到那里运行良好,此外,当我再次执行它时,它不会合并任何正常的东西。
现在我在某些值上手动更新表源{{ ref('salestarget') }},例如为TargetQuantity 设置一个新值,当我再次执行模型时,它应该检测到发生的更改并将其合并,因为新计算的校验和会和旧的不一样,但是不起作用,最后合并了0行。
我的校验和有什么问题吗?
【问题讨论】:
标签: google-bigquery dbt