AN-1201/tests (#18)

* tests

* docs

* date filter

* and

* events
This commit is contained in:
Jack Forgash 2022-05-19 17:53:07 -06:00 committed by GitHub
parent 24f877ec55
commit a956618336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 92 additions and 115 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,34 @@
{% test sequence_gaps(
model,
partition_by,
column_name
) %}
{%- set partition_sql = partition_by | join(", ") -%}
{%- set previous_column = "prev_" ~ column_name -%}
WITH source AS (
SELECT
{{ partition_sql + "," if partition_sql }}
{{ column_name }},
LAG(
{{ column_name }},
1
) over (
{{ "PARTITION BY " ~ partition_sql if partition_sql }}
ORDER BY
{{ column_name }} ASC
) AS {{ previous_column }}
FROM
{{ model }}
)
SELECT
{{ partition_sql + "," if partition_sql }}
{{ previous_column }},
{{ column_name }},
{{ column_name }} - {{ previous_column }}
- 1 AS gap
FROM
source
WHERE
{{ column_name }} - {{ previous_column }} <> 1
ORDER BY
gap DESC {% endtest %}

35
macros/tests/tx_gaps.sql Normal file
View File

@ -0,0 +1,35 @@
{% test tx_gaps(
model,
column_name,
column_block,
column_tx_count
) %}
WITH block_base AS (
SELECT
{{ column_block }},
{{ column_tx_count }}
FROM
{{ ref('silver__blocks') }}
),
model_name AS (
SELECT
{{ column_block }},
COUNT(
DISTINCT {{ column_name }}
) AS model_tx_count
FROM
{{ model }}
GROUP BY
{{ column_block }}
)
SELECT
block_base.{{ column_block }},
{{ column_tx_count }},
model_name.{{ column_block }},
model_tx_count
FROM
block_base
LEFT JOIN model_name
ON block_base.{{ column_block }} = model_name.{{ column_block }}
WHERE
{{ column_tx_count }} <> model_tx_count {% endtest %}

View File

@ -11,10 +11,11 @@ WITH silver_blocks AS (
*
FROM
{{ ref('silver__blocks') }}
WHERE
block_timestamp >= '2022-05-09'
{% if is_incremental() %}
WHERE
_ingested_at :: DATE >= CURRENT_DATE - 2
AND _ingested_at :: DATE >= CURRENT_DATE - 2
{% endif %}
),
gold_blocks AS (

View File

@ -4,6 +4,10 @@ version: 2
models:
- name: gold__blocks
description: Information about blocks on the FLOW network and corresponding metadata.
tests:
- sequence_gaps:
column_name: block_height
where: BLOCK_TIMESTAMP < CURRENT_DATE
columns:
- name: block_height

View File

@ -11,10 +11,11 @@ WITH silver_events AS (
*
FROM
{{ ref('silver__events') }}
WHERE
block_timestamp >= '2022-05-09'
{% if is_incremental() %}
WHERE
_ingested_at :: DATE >= CURRENT_DATE -2
AND _ingested_at :: DATE >= CURRENT_DATE -2
{% endif %}
),
silver_event_attributes AS (
@ -22,10 +23,11 @@ silver_event_attributes AS (
*
FROM
{{ ref('silver__event_attributes') }}
WHERE
block_timestamp >= '2022-05-09'
{% if is_incremental() %}
WHERE
_ingested_at :: DATE >= CURRENT_DATE -2
AND _ingested_at :: DATE >= CURRENT_DATE -2
{% endif %}
),
objs AS (

View File

@ -11,10 +11,11 @@ WITH silver_txs AS (
*
FROM
{{ ref('silver__transactions') }}
WHERE
block_timestamp >= '2022-05-09'
{% if is_incremental() %}
WHERE
_ingested_at :: DATE > CURRENT_DATE - 2
AND _ingested_at :: DATE > CURRENT_DATE - 2
{% endif %}
),
gold_txs AS (

View File

@ -17,6 +17,10 @@ models:
tests:
- not_null
- unique
- tx_gaps:
column_block: block_height
column_tx_count: tx_count
where: BLOCK_TIMESTAMP < CURRENT_DATE
- name: block_timestamp
description: "{{ doc('block_timestamp') }}"

View File

@ -8,7 +8,7 @@ models:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_height
columns:
- name: block_height
description: "{{ doc('block_height') }}"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long