From 3a61d048c861a0591a2295cda1c307f3b75cc0d4 Mon Sep 17 00:00:00 2001 From: Son Do Date: Tue, 13 Aug 2024 19:02:25 -0400 Subject: [PATCH] Fixed Ton models --- models/projects/ton/core/ez_ton_metrics.sql | 5 +++-- models/staging/ton/fact_ton_fundamental_metrics.sql | 10 +++++++--- models/staging/ton/fact_ton_transactions.sql | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/models/projects/ton/core/ez_ton_metrics.sql b/models/projects/ton/core/ez_ton_metrics.sql index e9227635..f4dc14cf 100644 --- a/models/projects/ton/core/ez_ton_metrics.sql +++ b/models/projects/ton/core/ez_ton_metrics.sql @@ -14,9 +14,10 @@ with date, txns as transaction_nodes from {{ ref("fact_ton_daa_txns_gas_gas_usd_revenue_revenue_native") }} - ), ton_apps_fundamental_data as ( + ), + ton_apps_fundamental_data as ( select - date, + date , dau , fees_native , txns diff --git a/models/staging/ton/fact_ton_fundamental_metrics.sql b/models/staging/ton/fact_ton_fundamental_metrics.sql index 0ff60030..c194efc1 100644 --- a/models/staging/ton/fact_ton_fundamental_metrics.sql +++ b/models/staging/ton/fact_ton_fundamental_metrics.sql @@ -5,14 +5,17 @@ with flatten_ton_transaction as ( select - true = all(array_agg(success)) as success + NOT ARRAY_CONTAINS(0, ARRAY_UNIQUE_AGG(success)) as success , trace_id , max(block_timestamp::date) as date - , min_by(transaction_account_interfaces, lt)[1] as interface + , min_by(transaction_account_interfaces, lt) as interfaces , min_by(transaction_account, lt) as first_account , min_by(transaction_account_workchain, lt) as workchain , sum(total_fees) as transaction_fees from {{ ref('fact_ton_transactions') }} + {% if is_incremental() %} + where block_timestamp::date > (select dateadd('day', -3, max(date)) from {{ this }}) + {% endif %} group by trace_id ), txns as ( SELECT @@ -34,7 +37,8 @@ dau as ( date , count(distinct first_account) as dau from flatten_ton_transaction - where success and interface like 'wallet_v%' + where success and interfaces[1] like 'wallet_v%' + group by date ) SELECT coalesce(fees.date, txns.date, dau.date) as date diff --git a/models/staging/ton/fact_ton_transactions.sql b/models/staging/ton/fact_ton_transactions.sql index e0773218..b27528ca 100644 --- a/models/staging/ton/fact_ton_transactions.sql +++ b/models/staging/ton/fact_ton_transactions.sql @@ -36,6 +36,7 @@ with raw_data as ( {{ source("PROD_LANDING", "raw_ton_transactions") }} {% if is_incremental() %} where TO_TIMESTAMP(parse_json(source_json):"utime") > (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) + and extraction_date > (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) {% endif %} ) select