Skip to content

Commit

Permalink
Merge pull request #69 from FlipsideCrypto/fix/stats
Browse files Browse the repository at this point in the history
fix stats inc logic
  • Loading branch information
eric-laurello authored Mar 1, 2024
2 parents 6275341 + 9b8940f commit 8eb5fe5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
28 changes: 21 additions & 7 deletions models/silver/stats/silver_stats__core_metrics_block_hourly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@
cluster_by = ['block_timestamp_hour::DATE'],
tags = ['core']
) }}
/* 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__blocks') }}
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',
Expand Down Expand Up @@ -35,13 +54,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
30 changes: 22 additions & 8 deletions models/silver/stats/silver_stats__core_metrics_hourly.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@
cluster_by = ['block_timestamp_hour::DATE'],
tags = ['core']
) }}
/* 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',
Expand Down Expand Up @@ -46,13 +65,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
1

0 comments on commit 8eb5fe5

Please sign in to comment.