在dbt中获取latest_partition_timestamp



我一直在尝试调试它,但我不明白为什么会出现错误。所以我写了这个宏,把最新的分区作为

{% macro latest_partition() %}
{%- call statement('latest_partition_query', True) -%}
SELECT TIMESTAMP_TRUNC(MAX(event_timestamp), DAY) AS latest_partition FROM {{ this }}
{%- endcall -%}
{%- set max_timestamp = load_result('latest_partition_query')['data'] -%}
{%- do return(max_timestamp) -%}
{% endmacro %}

这将max_timestamp的值给定为[(datetime.datetime(2022,10,26,0,0,tzinfo=datetime.timezone.utc(,(],但当我试图使用indexs[0]对其进行索引以获取时间戳时,会出现错误"None"没有属性"data"。不确定添加索引是如何使其无的

预期结果将只是datetime.datetime(2022,10,26,0,0,tzinfo=datetime.timezone.utc(部分

向其添加if_execute块

{% macro latest_partition() %}
{%- call statement('latest_partition_query', True) -%}
SELECT TIMESTAMP_TRUNC(MAX(event_timestamp), DAY) AS latest_partition FROM {{ this }}
{%- endcall -%}
{%- set results = load_result('latest_partition_query')-%}
{% if execute %}
{% set max_timestamp = results.data[0][0] %}
{% else %}
{% set max_timestamp = None %}
{% endif %}
{%do return(max_timestamp) %}
{% endmacro %}

最新更新