This commit is contained in:
WHYTEWYLL 2023-11-07 14:18:53 -03:00
parent b4bd71d271
commit e283e9e794
5 changed files with 49 additions and 14 deletions

View File

@ -0,0 +1,38 @@
{{ config(
materialized = 'incremental',
unique_key = 'day',
incremental_strategy = 'delete+insert',
tags = ['atlas']
) }}
WITH date_range AS (
SELECT
date_day as day
FROM {{ ref('silver__dates') }}
WHERE
{% if is_incremental() %}
date_day >= SYSDATE() - INTERVAL '3 DAY'
{% else %}
date_day >= '2021-01-01' -- first day of data
{% endif %}
AND date_day <= SYSDATE()::DATE
)
SELECT day,
COUNT(DISTINCT tx_signer) - COUNT(DISTINCT CASE WHEN first_tx >= day - INTERVAL '30 Days' AND first_tx < day THEN wallet END) AS Returning_MAAs,
COUNT(DISTINCT CASE WHEN first_tx >= day - INTERVAL '30 Days' AND first_tx < day THEN wallet END) AS New_MAAs,
COUNT(DISTINCT tx_signer) AS MAAs
FROM date_range a
LEFT OUTER JOIN (SELECT DISTINCT tx_signer, block_timestamp::date AS active_day
FROM {{ ref('silver__streamline_transactions_final') }}) b
ON active_day >= day - INTERVAL '30 DAYS'
AND active_day < day
JOIN (SELECT tx_signer AS wallet, MIN(block_timestamp) AS first_tx FROM {{ ref('silver__streamline_transactions_final') }} tr GROUP BY 1) c
ON b.tx_signer = c.wallet
GROUP BY 1
ORDER BY 1 DESC
-- 4.20 Mins all
-- 2.5 mins incremental

View File

@ -13,7 +13,7 @@ WITH date_range AS (
{% if is_incremental() %}
date_day >= SYSDATE() - INTERVAL '3 DAY'
{% else %}
date_day >= '2021-05-01' -- first day of data
date_day >= '2021-01-01' -- first day of data
{% endif %}
AND date_day <= SYSDATE()::DATE
)

View File

@ -15,5 +15,3 @@ models:
description: "{{ doc('tx_count')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_of_type:
type: integer

View File

@ -7,13 +7,12 @@ models:
columns:
- name: receiver_id
description: { { doc('receiver_id') } }
description: "{ { doc('receiver_id')}}"
tests:
- not_null
- unique
- name: tokens
description: { { doc('token_id ') } }
description: "The count of unique tokens that have been received by the receiver_id."
tests:
- not_null

View File

@ -7,19 +7,19 @@ models:
columns:
- name: action_id
description: { { doc('action_id') } }
description: "{{doc('action_id')}}"
tests:
- unique
- not_null
- name: day
description: { { doc('date') } }
description: "{{doc('date')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_date
- name: tx_hash
description: { { doc('tx_hash') } }
description: "{{doc('tx_hash')}}"
tests:
- not_null
@ -29,27 +29,27 @@ models:
- not_null
- name: receiver_id
description: { { doc('receiver_id') } }
description: "{{doc('receiver_id')}}"
tests:
- not_null
- name: signer_id
description: { { doc('signer_id') } }
description: "{{doc('signer_id')}}"
tests:
- not_null
- name: owner
description: { { doc('owner') } }
description: "The owner of the token, which is the signer_id for minting events and the receiver_id for transfers."
tests:
- not_null
- name: token_id
description: { { doc('token_id') } }
description: "{{doc('token_id')}}"
tests:
- not_null
- name: _inserted_timestamp
description: { { doc('_inserted_timestamp') } }
description: "{{doc('_inserted_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_column_values_to_be_increasing