Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply gap testing to prices table #7060

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion dbt_subprojects/tokens/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vars:
# These configurations specify where dbt should look for different types of files.
# You don't need to change these!
model-paths: ["models", "../../sources"]
# test-paths: ["tests"]
test-paths: ["tests"]
# seed-paths: ["seeds"]
macro-paths: ["macros", "../../dbt_macros"]

Expand Down
18 changes: 18 additions & 0 deletions dbt_subprojects/tokens/models/prices/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ models:
contributors: couralex, jeff-dude, 0xRob
config:
tags: [ 'prices', 'daily']
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- blockchain
- contract_address
- timestamp

- name: prices_hour
meta:
Expand Down Expand Up @@ -68,6 +74,12 @@ models:
contributors: couralex, jeff-dude, 0xRob
config:
tags: [ 'prices', 'hourly']
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- blockchain
- contract_address
- timestamp

- name: prices_minute
meta:
Expand Down Expand Up @@ -102,6 +114,12 @@ models:
contributors: couralex, jeff-dude, 0xRob
config:
tags: [ 'prices', 'minute']
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- blockchain
- contract_address
- timestamp

- name: prices_solana_hour
meta:
Expand Down
28 changes: 28 additions & 0 deletions dbt_subprojects/tokens/tests/assert_no_missing_prices_day.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
WITH token_time_range AS (
SELECT
blockchain,
contract_address,
symbol,
DATE(MIN(timestamp)) AS min_date,
DATE(MAX(timestamp)) AS max_date
FROM {{ ref('prices_day') }}
GROUP BY blockchain, contract_address, symbol
),
all_days AS (
SELECT DISTINCT DATE(timestamp) AS date
FROM {{ ref('prices_day') }}
)
SELECT
ad.date AS missing_date,
ttr.blockchain,
ttr.contract_address,
ttr.symbol
FROM token_time_range ttr
CROSS JOIN all_days ad
LEFT JOIN {{ ref('prices_day') }} p ON ad.date = DATE(p.timestamp)
AND ttr.blockchain = p.blockchain
AND ttr.contract_address = p.contract_address
AND ttr.symbol = p.symbol
WHERE p.timestamp IS NULL
AND ad.date BETWEEN ttr.min_date AND ttr.max_date

28 changes: 28 additions & 0 deletions dbt_subprojects/tokens/tests/assert_no_missing_prices_hour.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
WITH token_time_range AS (
SELECT
blockchain,
contract_address,
symbol,
MIN(timestamp) AS min_timestamp,
MAX(timestamp) AS max_timestamp
FROM {{ ref('prices_hour') }}
GROUP BY blockchain, contract_address, symbol
),
all_hours AS (
SELECT DISTINCT timestamp
FROM {{ ref('prices_hour') }}
)
SELECT
ah.timestamp AS missing_hour,
ttr.blockchain,
ttr.contract_address,
ttr.symbol
FROM token_time_range ttr
CROSS JOIN all_hours ah
LEFT JOIN {{ ref('prices_hour') }} p ON ah.timestamp = p.timestamp
AND ttr.blockchain = p.blockchain
AND ttr.contract_address = p.contract_address
AND ttr.symbol = p.symbol
WHERE p.timestamp IS NULL
AND ah.timestamp BETWEEN ttr.min_timestamp AND ttr.max_timestamp

28 changes: 28 additions & 0 deletions dbt_subprojects/tokens/tests/assert_no_missing_prices_minute.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
WITH token_time_range AS (
SELECT
blockchain,
contract_address,
symbol,
MIN(timestamp) AS min_timestamp,
MAX(timestamp) AS max_timestamp
FROM {{ ref('prices_minute') }}
GROUP BY blockchain, contract_address, symbol
),
all_minutes AS (
SELECT DISTINCT timestamp
FROM {{ ref('prices_minute') }}
)
SELECT
am.timestamp AS missing_minute,
ttr.blockchain,
ttr.contract_address,
ttr.symbol
FROM token_time_range ttr
CROSS JOIN all_minutes am
LEFT JOIN {{ ref('prices_minute') }} p ON am.timestamp = p.timestamp
AND ttr.blockchain = p.blockchain
AND ttr.contract_address = p.contract_address
AND ttr.symbol = p.symbol
WHERE p.timestamp IS NULL
AND am.timestamp BETWEEN ttr.min_timestamp AND ttr.max_timestamp

20 changes: 20 additions & 0 deletions dbt_subprojects/tokens/tests/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: 2

data_tests:
- name: assert_no_missing_price_day
description: >
Ensure that there are no missing prices for each token on each day
severity: error
tags: [ 'data_test', 'daily']

- name: assert_no_missing_price_hour
description: >
Ensure that there are no missing prices for each token on each hour
severity: error
tags: [ 'data_test', 'hourly']

- name: assert_no_missing_price_minute
description: >
Ensure that there are no missing prices for each token on each minute
severity: error
tags: [ 'data_test', 'minute']
Loading