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

Source rowcount generic test #3279

Merged
merged 8 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions models/_sector/nft/trades/ethereum/platforms/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns: ['block_number','tx_hash','sub_tx_trade_id']
- dbt_utils.equal_rowcount:
compare_model: source('archipelago_ethereum','ArchipelagoMarket_evt_Trade')
- dbt_utils.equal_rowcount:
compare_model: ref('archipelago_ethereum_events')
- equal_rowcount_with_sources:
evt_sources:
- source('archipelago_ethereum','ArchipelagoMarket_evt_Trade')
- check_seed:
seed_file: ref('archipelago_ethereum_base_trades_seed')
match_columns:
Expand Down Expand Up @@ -75,6 +76,12 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns: [ 'block_number','tx_hash','sub_tx_trade_id' ]
- equal_rowcount_with_sources:
evt_sources:
- source('foundation_ethereum','market_evt_ReserveAuctionFinalized')
- source('foundation_ethereum','market_evt_BuyPriceAccepted')
- source('foundation_ethereum','market_evt_OfferAccepted')
- source('foundation_ethereum','market_evt_PrivateSaleFinalized')
Comment on lines +79 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so this part can test the sum of events from multiple event sources.

- check_seed:
seed_file: ref('foundation_ethereum_base_trades_seed')
match_columns:
Expand Down
24 changes: 0 additions & 24 deletions tests/_sector/nft/check_nft_rowcount_foundation.sql

This file was deleted.

27 changes: 27 additions & 0 deletions tests/generic/equal_rowcount_with_sources.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% test equal_rowcount_with_sources(model, evt_sources=[]) %}

WITH
model_count as (
select count(*) as count_a from {{ model }}
)
,sources_count as (
select sum(count_b) as count_b
from (
{% for source in evt_sources %}
select count(*) as count_b
from {{ source }}
where evt_block_time <= (select max(block_time) from {{ model }})
{% if not loop.last %} UNION ALL {% endif %}
{% endfor %}
) b
)

,unit_test as (
select count_a, count_b, (count_a - count_b) as diff_count
from model_count
full outer join sources_count
on 1=1
)

select * from unit_test where diff_count > 0
Comment on lines +20 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to write abs(count_a - count_b) as diff_count?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea!

{% endtest %}