flow-models/tests/tests__streamline_transactions_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

76 lines
1.8 KiB
SQL

{{ config(
severity = 'error',
tags = ['streamline_test']
) }}
WITH transactions_expected AS (
SELECT
block_number AS block_height,
SUM(tx_count) AS txs_count,
ARRAY_AGG(collection_id) AS collections_expected,
array_union_agg(transaction_ids) AS txs_expected,
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
),
transactions_actual AS (
SELECT
block_number AS block_height,
COUNT(
DISTINCT tx_id
) AS txs_count,
ARRAY_AGG(
DISTINCT tx_id
) AS txs_actual,
MAX(_inserted_timestamp) AS _inserted_timestamp
FROM
{{ ref('silver__streamline_transactions') }}
{% 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.txs_count AS expected,
COALESCE(
A.txs_count,
0
) AS actual,
expected - actual AS difference,
silver.udf_array_disjunctive_union(
e.txs_expected,
COALESCE(
A.txs_actual,
ARRAY_CONSTRUCT()
)
) AS txs_missing,
A._inserted_timestamp AS _inserted_timestamp
FROM
transactions_expected e
LEFT JOIN transactions_actual A USING(block_height)
WHERE
expected != actual
AND A._inserted_timestamp <= SYSDATE() - INTERVAL '1 day'
ORDER BY
1