diff --git a/models/terra/silver/silver_terra__msg_events.sql b/models/terra/silver/silver_terra__msg_events.sql index 86e1bea6..190ad41c 100644 --- a/models/terra/silver/silver_terra__msg_events.sql +++ b/models/terra/silver/silver_terra__msg_events.sql @@ -1,17 +1,37 @@ -{{ - config( - materialized='incremental', - unique_key='chain_id || block_id || tx_id || msg_index || event_index || event_type', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp', 'block_id', 'tx_id'], - tags=['snowflake', 'terra_silver', 'terra_msg_events'] - ) -}} +{{ config( + materialized = 'incremental', + unique_key = 'chain_id || block_id || tx_id || msg_index || event_index || event_type', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id', 'tx_id'], + tags = ['snowflake', 'terra_silver', 'terra_msg_events'] +) }} + +SELECT + * +FROM + ( + SELECT + * + FROM + {{ ref('terra_dbt__msg_events') }} + WHERE + 1 = 1 -select * -from {{ ref('terra_dbt__msg_events')}} -WHERE 1=1 {% if is_incremental() %} - AND system_created_at::date >= (select dateadd('day',-1,max(system_created_at::date)) from {{source('silver_terra', 'msg_events')}}) +AND system_created_at :: DATE >= ( + SELECT + DATEADD('day', -1, MAX(system_created_at :: DATE)) + FROM + {{ source( + 'silver_terra', + 'msg_events' + ) }} +) {% endif %} -QUALIFY(row_number() over(partition by chain_id, block_id, tx_id, msg_index, event_index, event_type order by system_created_at desc)) = 1 + +qualify(RANK() over(PARTITION BY tx_id +ORDER BY + block_id DESC)) = 1 +) qualify(ROW_NUMBER() over(PARTITION BY chain_id, block_id, tx_id, msg_index, event_index, event_type +ORDER BY + system_created_at DESC)) = 1 diff --git a/models/terra/silver/silver_terra__msgs.sql b/models/terra/silver/silver_terra__msgs.sql index bf9149b6..92d6b400 100644 --- a/models/terra/silver/silver_terra__msgs.sql +++ b/models/terra/silver/silver_terra__msgs.sql @@ -1,17 +1,39 @@ -{{ - config( - materialized='incremental', - unique_key='chain_id || block_id || tx_id || msg_index', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp', 'block_id', 'tx_id'], - tags=['snowflake', 'terra_silver', 'terra_msgs'] - ) -}} +{{ config( + materialized = 'incremental', + unique_key = 'chain_id || block_id || tx_id || msg_index', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id', 'tx_id'], + tags = ['snowflake', 'terra_silver', 'terra_msgs'] +) }} + +SELECT + * +FROM + ( + SELECT + * + FROM + {{ ref('terra_dbt__msgs') }} + WHERE + 1 = 1 -select * -from {{ ref('terra_dbt__msgs')}} -WHERE 1=1 {% if is_incremental() %} - AND system_created_at::date >= (select dateadd('day',-1,max(system_created_at::date)) from {{source('silver_terra', 'msgs')}}) +AND system_created_at :: DATE >= ( + SELECT + DATEADD('day', -1, MAX(system_created_at :: DATE)) + FROM + {{ source( + 'silver_terra', + 'msgs' + ) }} +) {% endif %} -QUALIFY(row_number() over(partition by chain_id, block_id, tx_id, msg_index order by system_created_at desc)) = 1 + +qualify(RANK() over(PARTITION BY tx_id +ORDER BY + block_id DESC)) = 1 +) + +qualify(ROW_NUMBER() over(PARTITION BY chain_id, block_id, tx_id, msg_index +ORDER BY + system_created_at DESC)) = 1 diff --git a/models/terra/silver/silver_terra__transactions.sql b/models/terra/silver/silver_terra__transactions.sql index 02d979a8..81e168ea 100644 --- a/models/terra/silver/silver_terra__transactions.sql +++ b/models/terra/silver/silver_terra__transactions.sql @@ -1,17 +1,37 @@ -{{ - config( - materialized='incremental', - unique_key='chain_id || block_id || tx_id', - incremental_strategy='delete+insert', - cluster_by=['block_timestamp', 'block_id'], - tags=['snowflake', 'terra_silver', 'terra_transactions'] - ) -}} +{{ config( + materialized = 'incremental', + unique_key = 'chain_id || block_id || tx_id', + incremental_strategy = 'delete+insert', + cluster_by = ['block_timestamp', 'block_id'], + tags = ['snowflake', 'terra_silver', 'terra_transactions'] +) }} + +SELECT + * +FROM + ( + SELECT + * + FROM + {{ ref('terra_dbt__transactions') }} + WHERE + 1 = 1 -select * -from {{ ref('terra_dbt__transactions')}} -WHERE 1=1 {% if is_incremental() %} - AND system_created_at::date >= (select dateadd('day',-1,max(system_created_at::date)) from {{source('silver_terra', 'transactions')}}) +AND system_created_at :: DATE >= ( + SELECT + DATEADD('day', -1, MAX(system_created_at :: DATE)) + FROM + {{ source( + 'silver_terra', + 'transactions' + ) }} +) {% endif %} -QUALIFY(row_number() over(partition by chain_id, block_id, tx_id order by system_created_at desc)) = 1 \ No newline at end of file + +qualify(RANK() over(PARTITION BY tx_id +ORDER BY + block_id DESC)) = 1 +) qualify(ROW_NUMBER() over(PARTITION BY chain_id, block_id, tx_id +ORDER BY + system_created_at DESC)) = 1