flow-models/tests/tests__streamline_collections_gap.sql
Jack Forgash 792f11599f
AN-3903/Migration Reorg (#196)
* txs final and upd streamline tests w 1 hr inserted timestamp buffer

* copy silver models into silver_cw dir

* txs final, events model, curated model _s copies

* add pending col to txs final

* test config for pending_result_response

* add coalesce to tx id in txs final

* rem tests on inserted timestamp

* uppercase gap test vars

* add retry for null block timestamp and del mainnet23 filter from events

* address adj append 0x, add network ver to blocks, etc

* upd coalesce on events data

* saving event migration test, disabled

* req changes

* upd txs final ingested logic
2023-10-10 13:24:43 -06:00

75 lines
1.8 KiB
SQL

{{ config(
severity = 'error',
tags = ['streamline_test']
) }}
WITH collections_expected AS (
SELECT
block_height,
collection_count,
ARRAY_AGG(
VALUE :collection_id :: STRING
) AS collections_expected,
MAX(_inserted_timestamp) AS _inserted_timestamp
FROM
{{ ref('silver__streamline_blocks') }},
LATERAL FLATTEN(collection_guarantees) {% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('START_HEIGHT', Null) }}
AND {{ var('END_HEIGHT', Null) }}
{% endif %}
GROUP BY
1,
2
),
collections_actual AS (
SELECT
block_number AS block_height,
COUNT(
DISTINCT collection_id
) AS collection_count,
ARRAY_AGG(collection_id) AS collections_actual,
MAX(_inserted_timestamp) AS _inserted_timestamp
FROM
{{ ref('silver__streamline_collections') }}
{% if var(
'TEST_RANGE',
False
) %}
WHERE
block_height BETWEEN {{ var('START_HEIGHT', Null) }}
AND {{ var('END_HEIGHT', Null) }}
{% endif %}
GROUP BY
1
)
SELECT
e.block_height,
e.collection_count AS expected,
COALESCE(
A.collection_count,
0
) AS actual,
expected - actual AS difference,
silver.udf_array_disjunctive_union(
e.collections_expected,
COALESCE(
A.collections_actual,
ARRAY_CONSTRUCT()
)
) AS missing_collections,
A._inserted_timestamp
FROM
collections_expected e
LEFT JOIN collections_actual A USING(block_height)
WHERE
expected != actual
AND A._inserted_timestamp <= SYSDATE() - INTERVAL '1 day'
ORDER BY
1