From 7608c1c611dc565148869793910cce6d32d56e4c Mon Sep 17 00:00:00 2001 From: Jack Forgash <58153492+forgxyz@users.noreply.github.com> Date: Fri, 1 Sep 2023 15:03:15 -0600 Subject: [PATCH] add last_3_days filter, rem tbl (#177) * add last_3_days filter, rem tbl * max * rem max --- .../streamline__get_collections_realtime.sql | 49 +++---------------- ...line__get_transaction_results_realtime.sql | 35 +------------ .../streamline__get_transactions_realtime.sql | 35 +------------ 3 files changed, 12 insertions(+), 107 deletions(-) diff --git a/models/silver/streamline/core/realtime/streamline__get_collections_realtime.sql b/models/silver/streamline/core/realtime/streamline__get_collections_realtime.sql index 015de7b..75211f8 100644 --- a/models/silver/streamline/core/realtime/streamline__get_collections_realtime.sql +++ b/models/silver/streamline/core/realtime/streamline__get_collections_realtime.sql @@ -19,47 +19,7 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %} FROM {{ ref('streamline__blocks') }} {% endif %}), - tbl AS ( - SELECT - block_height - FROM - {{ ref('streamline__blocks') }} - WHERE - ( - block_height >= ( - SELECT - block_height - FROM - last_3_days - ) - ) - AND block_height IS NOT NULL - EXCEPT - SELECT - block_number AS block_height - FROM - {{ ref('streamline__complete_get_collections') }} - WHERE - ( - block_height >= ( - SELECT - block_height - FROM - last_3_days - ) - ) - AND block_height IS NOT NULL - ), - collections AS ( - SELECT - block_number AS block_height, - DATA - FROM - {{ ref('streamline__complete_get_blocks') }} - JOIN tbl - ON tbl.block_height = block_number - ), - -- CTE to get all block_heights and their associated collection_ids from the complete_get_blocks table + -- CTE to get targeted block_heights and their associated collection_ids from the complete_get_blocks table block_collections AS ( SELECT cb.block_number AS block_height, @@ -70,6 +30,13 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %} LATERAL FLATTEN( input => cb.data :collection_guarantees ) AS collection_guarantee + WHERE + block_height >= ( + SELECT + block_height + FROM + last_3_days + ) ), -- CTE to identify collections that haven't been ingested yet collections_to_ingest AS ( diff --git a/models/silver/streamline/core/realtime/streamline__get_transaction_results_realtime.sql b/models/silver/streamline/core/realtime/streamline__get_transaction_results_realtime.sql index dba5f81..6501612 100644 --- a/models/silver/streamline/core/realtime/streamline__get_transaction_results_realtime.sql +++ b/models/silver/streamline/core/realtime/streamline__get_transaction_results_realtime.sql @@ -19,37 +19,6 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %} FROM {{ ref('streamline__blocks') }} {% endif %}), - tbl AS ( - SELECT - block_height - FROM - {{ ref('streamline__blocks') }} - WHERE - ( - block_height >= ( - SELECT - block_height - FROM - last_3_days - ) - ) - AND block_height IS NOT NULL - EXCEPT - SELECT - block_number AS block_height - FROM - {{ ref('streamline__complete_get_transactions') }} - WHERE - ( - block_height >= ( - SELECT - block_height - FROM - last_3_days - ) - ) - AND block_height IS NOT NULL - ), collection_transactions AS ( SELECT block_number AS block_height, @@ -61,11 +30,11 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %} input => cc.data :transaction_ids ) AS TRANSACTION WHERE - block_height IN ( + block_height >= ( SELECT block_height FROM - tbl + last_3_days ) ), -- CTE to identify transactions that haven't been ingested yet diff --git a/models/silver/streamline/core/realtime/streamline__get_transactions_realtime.sql b/models/silver/streamline/core/realtime/streamline__get_transactions_realtime.sql index 2cbd70b..c0474f4 100644 --- a/models/silver/streamline/core/realtime/streamline__get_transactions_realtime.sql +++ b/models/silver/streamline/core/realtime/streamline__get_transactions_realtime.sql @@ -19,37 +19,6 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %} FROM {{ ref('streamline__blocks') }} {% endif %}), - tbl AS ( - SELECT - block_height - FROM - {{ ref('streamline__blocks') }} - WHERE - ( - block_height >= ( - SELECT - block_height - FROM - last_3_days - ) - ) - AND block_height IS NOT NULL - EXCEPT - SELECT - block_number AS block_height - FROM - {{ ref('streamline__complete_get_transactions') }} - WHERE - ( - block_height >= ( - SELECT - block_height - FROM - last_3_days - ) - ) - AND block_height IS NOT NULL - ), collection_transactions AS ( SELECT block_number AS block_height, @@ -61,11 +30,11 @@ WITH last_3_days AS ({% if var('STREAMLINE_RUN_HISTORY') %} input => cc.data :transaction_ids ) AS TRANSACTION WHERE - block_height IN ( + block_height >= ( SELECT block_height FROM - tbl + last_3_days ) ), -- CTE to identify transactions that haven't been ingested yet