From 6d515ab2efad931346271dcc128314ccd5912713 Mon Sep 17 00:00:00 2001 From: drethereum <71602799+drethereum@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:34:38 -0700 Subject: [PATCH] fix/core-stats-inc (#134) inc --- .../silver_stats__core_metrics_hourly.sql | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/models/silver/stats/silver_stats__core_metrics_hourly.sql b/models/silver/stats/silver_stats__core_metrics_hourly.sql index c5bd1b86..d16c1bb7 100644 --- a/models/silver/stats/silver_stats__core_metrics_hourly.sql +++ b/models/silver/stats/silver_stats__core_metrics_hourly.sql @@ -5,7 +5,26 @@ cluster_by = ['block_timestamp_hour::DATE'], tags = ['curated'] ) }} +/* run incremental timestamp value first then use it as a static value */ +{% if execute %} +{% if is_incremental() %} +{% set query %} + +SELECT + MIN(DATE_TRUNC('hour', block_timestamp)) block_timestamp_hour +FROM + {{ ref('silver__transactions') }} +WHERE + _inserted_timestamp >= ( + SELECT + MAX(_inserted_timestamp) + FROM + {{ this }} + ) {% endset %} + {% set min_block_timestamp_hour = run_query(query).columns [0].values() [0] %} +{% endif %} +{% endif %} SELECT DATE_TRUNC( 'hour', @@ -54,13 +73,8 @@ WHERE {% if is_incremental() %} AND DATE_TRUNC( 'hour', - _inserted_timestamp -) >= ( - SELECT - MAX(DATE_TRUNC('hour', _inserted_timestamp)) - INTERVAL '12 hours' - FROM - {{ this }} -) + block_timestamp +) >= '{{ min_block_timestamp_hour }}' {% endif %} GROUP BY 1