我们的 dbt_project.yml 文件 config-version: 1 有两个跨不同增量模型的变量,我们使用一个名为today()的宏
vars:
start_date: '{{ today(offset_days=-1) }}'
end_date: '2999-12-31'
在测试迁移到 dbt 0.17.2, config-version:2 时,我们面临以下问题
Running with dbt=0.17.2
Encountered an error:
Compilation Error
Could not render {{ today(offset_days=-1) }}: 'today' is undefined
我们去年年底构建的宏。我相信 dbt 改变了宏变量的引用方式,但不知道如何解决这个问题。
-- returns current hour in YYYY-MM-DD-HH format,
-- optionally offset by N days (-N or +N) or M hours (-M or +M)
{%- macro current_hour(offset_days=0, offset_hours=0) -%}
{%- set now = modules.datetime.datetime.now(modules.pytz.utc) -%}
{%- set dt = now + modules.datetime.timedelta(days=offset_days, hours=offset_hours) -%}
{{- dt.strftime("%Y-%m-%d-%H") -}}
{%- endmacro -%}
-- returns current day in YYYY-MM-DD format,
-- optionally offset by N days (-N or +N) or M hours (-M or +M)
{%- macro today(offset_days=0, offset_hours=0) -%}
{{- current_hour(offset_days, offset_hours)[0:10] -}}
{%- endmacro -%}
-- accepts a timestamp string and returns a timestamo string
-- formatted like 'YYYY-MM-DD HH24:MI:SS.US', e.g. '2019-11-02 06:11:42.690000'
{%- macro dt_to_utc(ts_string) -%}
TO_CHAR({{ ts_string }}::TIMESTAMPTZ, 'YYYY-MM-DD HH24:MI:SS.US')
{%- endmacro -%}