external-models/models/artemis/gold/artemis__tx_count.sql
Stanley dc442db717
AN-5829-Artemis (#98)
Co-authored-by: Eric Laurello <eric.laurello@flipsidecrypto.com>
2025-04-10 23:11:12 +07:00

35 lines
980 B
SQL

{{ config(
materialized = 'incremental',
unique_key = ['block_date', 'blockchain', 'metric'],
tags = ['artemis']
) }}
SELECT
blockchain,
'tx_count' AS metric,
'The reported number of transactions as of the block_date' AS description,
metric_date AS block_date,
metric_value AS tx_count,
_inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['blockchain', 'metric', 'block_date']) }} AS tx_count_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM
{{ ref('silver__artemis') }}
WHERE
metric = 'daily_txns'
AND metric_value IS NOT NULL
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT COALESCE(MAX(_inserted_timestamp), '1970-01-01'::TIMESTAMP_NTZ)
FROM {{ this }}
)
{% endif %}
QUALIFY ROW_NUMBER() OVER (
PARTITION BY tx_count_id
ORDER BY
_inserted_timestamp DESC
) = 1