-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix: Coalesce incremental fields (#87)
* Coalesce Incremental Load Fields in `shopify__customer_cohorts` (#86) * coalesce incremental load values * coalesce windows columns * validation tests + docs * CHANGELOG --------- Co-authored-by: advolut-team <[email protected]>
- Loading branch information
1 parent
3888e08
commit 470b8da
Showing
11 changed files
with
146 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
packages: | ||
- local: ../ | ||
- local: ../ |
54 changes: 54 additions & 0 deletions
54
integration_tests/tests/consistency/consistency_customer_cohorts.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
with prod as ( | ||
|
||
select | ||
customer_cohort_id, | ||
source_relation, | ||
total_price_lifetime, | ||
order_count_lifetime, | ||
line_item_count_lifetime | ||
from {{ target.schema }}_shopify_prod.shopify__customer_cohorts | ||
), | ||
|
||
dev as ( | ||
|
||
select | ||
customer_cohort_id, | ||
source_relation, | ||
total_price_lifetime, | ||
order_count_lifetime, | ||
line_item_count_lifetime | ||
from {{ target.schema }}_shopify_dev.shopify__customer_cohorts | ||
), | ||
|
||
final as ( | ||
|
||
select | ||
prod.customer_cohort_id as prod_customer_cohort_id, | ||
dev.customer_cohort_id as dev_customer_cohort_id, | ||
prod.source_relation as prod_source_relation, | ||
dev.source_relation as dev_source_relation, | ||
prod.total_price_lifetime as prod_total_price_lifetime, | ||
dev.total_price_lifetime as dev_total_price_lifetime, | ||
prod.order_count_lifetime as prod_order_count_lifetime, | ||
dev.order_count_lifetime as dev_order_count_lifetime, | ||
prod.line_item_count_lifetime as prod_line_item_count_lifetime, | ||
dev.line_item_count_lifetime as dev_line_item_count_lifetime | ||
from prod | ||
full outer join dev | ||
on dev.customer_cohort_id = prod.customer_cohort_id | ||
and dev.source_relation = prod.source_relation | ||
) | ||
|
||
select * | ||
from final | ||
where | ||
prod_customer_cohort_id != dev_customer_cohort_id or | ||
prod_source_relation != dev_source_relation or | ||
abs(prod_total_price_lifetime - dev_total_price_lifetime) > .001 or | ||
abs(prod_order_count_lifetime - dev_order_count_lifetime) > .001 or | ||
abs(prod_line_item_count_lifetime - dev_line_item_count_lifetime) > .001 |
61 changes: 61 additions & 0 deletions
61
integration_tests/tests/integrity/vertical_integrity_customer_cohorts.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
with calendar as ( | ||
|
||
select * | ||
from {{ ref('shopify__calendar') }} | ||
where cast({{ dbt.date_trunc('month','date_day') }} as date) = date_day | ||
|
||
), | ||
|
||
customers as ( | ||
|
||
select * | ||
from {{ ref('shopify__customers') }} | ||
|
||
), | ||
|
||
orders as ( | ||
|
||
select * | ||
from {{ ref('shopify__orders') }} | ||
|
||
), | ||
|
||
customer_cohort_source as ( | ||
|
||
select | ||
customers.source_relation, | ||
count(*) as source_rows | ||
from calendar | ||
inner join customers | ||
on cast({{ dbt.date_trunc('month', 'first_order_timestamp') }} as date) <= calendar.date_day | ||
group by 1 | ||
), | ||
|
||
customer_cohort_end as ( | ||
|
||
select | ||
source_relation, | ||
count(*) as end_rows | ||
from {{ ref('shopify__customer_cohorts') }} | ||
group by 1 | ||
), | ||
|
||
final as ( | ||
select | ||
customer_cohort_source.source_relation, | ||
source_rows, | ||
end_rows | ||
from customer_cohort_source | ||
join customer_cohort_end | ||
on customer_cohort_source.source_relation = customer_cohort_end.source_relation | ||
where customer_cohort_source.source_rows != customer_cohort_end.end_rows | ||
) | ||
|
||
select * | ||
from final | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters