-
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.
* Update shopify__daily_shop.sql Update code to include new 'delayed' status from Shopify * Bump package version * Update CHANGELOG.md * Bump project version * Update link to PR in changelog * testing * validation tests * docs * joe feedback * change package ref * avinash feedback --------- Co-authored-by: Brent Shreve <[email protected]>
- Loading branch information
1 parent
fc20889
commit 9dc9de3
Showing
15 changed files
with
269 additions
and
20 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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
id,_fivetran_synced,address_1,city,country,created_at,estimated_delivery_at,fulfillment_id,happened_at,latitude,longitude,message,order_id,province,shop_id,status,updated_at,zip,_fivetran_deleted | ||
451435,2022-11-18 04:39:07.945000,,,,2022-08-29 20:52:39.000000,,40495,2022-08-29 20:52:39.000000,,,,4502987,,89440612,delivered,2022-08-29 20:52:39.000000,,false | ||
48779,2022-11-18 05:48:01.773000,,LONDON,GB,2022-09-13 08:07:57.000000,,4064737,2022-08-15 12:41:00.000000,101.349998474121094,-14.0333000011742115,Delay,4588203,,320612,out_for_delivery,2022-09-13 08:07:57.000000,CR0,false | ||
1481515,2022-11-18 05:41:00.745000,,ECHO PARK,AU,2022-09-14 14:16:52.000000,2022-09-14 08:00:00.000000,4019339,2022-09-14 01:26:00.000000,-3.797698974609375,190.783958203125,Delay,451915,,89320612,out_for_delivery,2022-09-14 14:16:52.000000,2759,false | ||
1481515,2022-11-18 05:41:00.745000,,ECHO PARK,AU,2022-09-14 14:16:52.000000,2022-09-14 08:00:00.000000,4019339,2022-09-14 01:26:00.000000,-3.797698974609375,190.783958203125,Delay,451915,,89320612,delayed,2022-09-14 14:16:52.000000,2759,false | ||
558955,2022-11-18 10:51:24.286000,,LAZYTOWN,US,2022-08-13 12:40:26.000000,,402947,2022-03-01 10:36:39.000000,22.337699890136719,-71.731002807617188,Delay,429188587,MA,89420612,in_transit,2022-08-13 12:40:26.000000,01505,false | ||
6904235,2022-11-18 08:58:00.458000,,LA,US,2022-08-24 06:29:21.000000,2022-08-24 23:59:59.000000,4060491,2022-08-24 05:30:57.000000,12.287498474121094,-21.3573989868164,Delay,4242667,MA,89420612,in_transit,2022-08-24 06:29:21.000000,01760,false |
91 changes: 91 additions & 0 deletions
91
integration_tests/tests/consistency/consistency_daily_shop.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,91 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
with prod as ( | ||
select | ||
date_day, | ||
shop_id, | ||
source_relation, | ||
sum(count_orders) as count_orders, | ||
count(count_customers) as count_customers, | ||
sum(order_adjusted_total) as order_adjusted_total, | ||
sum(count_abandoned_checkouts) as count_abandoned_checkouts | ||
|
||
{% if var('shopify_using_fulfillment_event', false) %} | ||
, sum(count_fulfillment_attempted_delivery) as count_fulfillment_attempted_delivery | ||
, sum(count_fulfillment_confirmed) as count_fulfillment_confirmed | ||
, count(count_fulfillment_in_transit) as count_fulfillment_in_transit | ||
{% endif %} | ||
|
||
from {{ target.schema }}_shopify_prod.shopify__daily_shop | ||
group by 1,2,3 | ||
), | ||
|
||
dev as ( | ||
select | ||
date_day, | ||
shop_id, | ||
source_relation, | ||
sum(count_orders) as count_orders, | ||
count(count_customers) as count_customers, | ||
sum(order_adjusted_total) as order_adjusted_total, | ||
sum(count_abandoned_checkouts) as count_abandoned_checkouts | ||
|
||
{% if var('shopify_using_fulfillment_event', false) %} | ||
, sum(count_fulfillment_attempted_delivery) as count_fulfillment_attempted_delivery | ||
, sum(count_fulfillment_confirmed) as count_fulfillment_confirmed | ||
, count(count_fulfillment_in_transit) as count_fulfillment_in_transit | ||
{% endif %} | ||
|
||
from {{ target.schema }}_shopify_dev.shopify__daily_shop | ||
group by 1,2,3 | ||
), | ||
|
||
final as ( | ||
select | ||
prod.date_day as prod_date_day, | ||
dev.date_day as dev_date_day, | ||
prod.shop_id as prod_shop_id, | ||
dev.shop_id as dev_shop_id, | ||
prod.source_relation as prod_source_relation, | ||
dev.source_relation as dev_source_relation, | ||
prod.count_orders as prod_count_orders, | ||
dev.count_orders as dev_count_orders, | ||
prod.count_customers as prod_count_customers, | ||
dev.count_customers as dev_count_customers, | ||
prod.order_adjusted_total as prod_order_adjusted_total, | ||
dev.order_adjusted_total as dev_order_adjusted_total, | ||
prod.count_abandoned_checkouts as prod_count_abandoned_checkouts, | ||
dev.count_abandoned_checkouts as dev_count_abandoned_checkouts | ||
|
||
{% if var('shopify_using_fulfillment_event', false) %} | ||
, prod.count_fulfillment_attempted_delivery as prod_count_fulfillment_attempted_delivery | ||
, dev.count_fulfillment_attempted_delivery as dev_count_fulfillment_attempted_delivery | ||
, prod.count_fulfillment_confirmed as prod_count_fulfillment_confirmed | ||
, dev.count_fulfillment_confirmed as dev_count_fulfillment_confirmed | ||
{% endif %} | ||
|
||
from prod | ||
full outer join dev | ||
on dev.date_day = prod.date_day | ||
and dev.shop_id = prod.shop_id | ||
and dev.source_relation = prod.source_relation | ||
) | ||
|
||
select * | ||
from final | ||
where | ||
prod_date_day != dev_date_day or | ||
prod_shop_id != dev_shop_id or | ||
prod_source_relation != dev_source_relation or | ||
abs(prod_count_orders - dev_count_orders) > .001 or | ||
abs(prod_count_customers - dev_count_customers) > .001 or | ||
abs(prod_order_adjusted_total - dev_order_adjusted_total) > .001 or | ||
abs(prod_count_abandoned_checkouts - dev_count_abandoned_checkouts) > .001 | ||
|
||
{% if var('shopify_using_fulfillment_event', false) %} | ||
or abs(prod_count_fulfillment_attempted_delivery - dev_count_fulfillment_attempted_delivery) > .001 | ||
or abs(prod_count_fulfillment_confirmed - dev_count_fulfillment_confirmed) > .001 | ||
{% endif %} |
63 changes: 63 additions & 0 deletions
63
integration_tests/tests/integrity/horizontal_integrity_daily_shop_orders.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,63 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
with orders as ( | ||
|
||
select * | ||
from {{ ref('shopify__orders') }} | ||
), | ||
|
||
order_metrics as ( | ||
|
||
select | ||
source_relation, | ||
cast({{ dbt.date_trunc('day','created_timestamp') }} as date) as date_day, | ||
count(distinct order_id) as count_orders, | ||
sum(order_adjusted_total) as order_adjusted_total | ||
|
||
from orders | ||
where created_timestamp > '2020-01-01' and created_timestamp < '2024-06-10' | ||
group by 1,2 | ||
), | ||
|
||
daily_shop as ( | ||
|
||
select * | ||
from {{ ref('shopify__daily_shop') }} | ||
), | ||
|
||
daily_shop_metrics as ( | ||
|
||
select | ||
source_relation, | ||
date_day, | ||
sum(count_orders) as count_orders, | ||
sum(order_adjusted_total) as order_adjusted_total | ||
|
||
from daily_shop | ||
where date_day >= '2020-01-01' and date_day < '2024-06-10' | ||
group by 1,2 | ||
), | ||
|
||
final as ( | ||
|
||
select | ||
daily_shop_metrics.source_relation, | ||
coalesce(daily_shop_metrics.count_orders, 0) as daily_shop_count_orders, | ||
coalesce(order_metrics.count_orders, 0) as order_count_orders, | ||
coalesce(daily_shop_metrics.order_adjusted_total, 0) as daily_shop_order_adjusted_total, | ||
coalesce(order_metrics.order_adjusted_total, 0) as order_order_adjusted_total | ||
|
||
from daily_shop_metrics | ||
full outer join order_metrics | ||
on daily_shop_metrics.source_relation = order_metrics.source_relation | ||
and daily_shop_metrics.date_day = order_metrics.date_day | ||
) | ||
|
||
select * | ||
from final | ||
where | ||
abs(daily_shop_count_orders - order_count_orders) > 0 or | ||
abs(daily_shop_order_adjusted_total - order_order_adjusted_total) > .1 |
81 changes: 81 additions & 0 deletions
81
integration_tests/tests/integrity/vertical_integrity_daily_shop_fulfillment.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,81 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
-- test will only run if shopify_using_fulfillment_event is set to True | ||
|
||
with source as ( | ||
|
||
select * | ||
from {{ ref('stg_shopify__fulfillment_event') }} | ||
), | ||
|
||
source_metrics as ( | ||
|
||
select | ||
source_relation, | ||
cast({{ dbt.date_trunc('day','happened_at') }} as date) as date_day, | ||
shop_id, | ||
count(distinct case when status = 'delayed' then fulfillment_id end) as count_fulfillment_delayed, | ||
count(distinct case when status = 'in_transit' then fulfillment_id end) as count_fulfillment_in_transit, | ||
count(distinct case when status = 'confirmed' then fulfillment_id end) as count_fulfillment_confirmed, | ||
count(distinct case when status = 'delivered' then fulfillment_id end) as count_fulfillment_delivered | ||
|
||
from source | ||
where happened_at > '2020-01-01' and happened_at < '2024-06-10' | ||
group by 1,2,3 | ||
), | ||
|
||
model as ( | ||
|
||
select * | ||
from {{ ref('shopify__daily_shop') }} | ||
), | ||
|
||
model_metrics as ( | ||
|
||
select | ||
source_relation, | ||
date_day, | ||
shop_id, | ||
sum(count_fulfillment_delayed) as count_fulfillment_delayed, | ||
sum(count_fulfillment_in_transit) as count_fulfillment_in_transit, | ||
sum(count_fulfillment_confirmed) as count_fulfillment_confirmed, | ||
sum(count_fulfillment_delivered) as count_fulfillment_delivered | ||
|
||
from model | ||
where date_day >= '2020-01-01' and date_day < '2024-06-10' | ||
group by 1,2,3 | ||
), | ||
|
||
final as ( | ||
|
||
select | ||
model_metrics.source_relation, | ||
model_metrics.shop_id as model_shop_id, | ||
source_metrics.shop_id as source_shop_id, | ||
model_metrics.date_day as model_date_day, | ||
source_metrics.date_day as source_date_day, | ||
coalesce(model_metrics.count_fulfillment_delayed, 0) as model_count_fulfillment_delayed, | ||
coalesce(source_metrics.count_fulfillment_delayed, 0) as source_count_fulfillment_delayed, | ||
coalesce(model_metrics.count_fulfillment_in_transit, 0) as model_count_fulfillment_in_transit, | ||
coalesce(source_metrics.count_fulfillment_in_transit, 0) as source_count_fulfillment_in_transit, | ||
coalesce(model_metrics.count_fulfillment_confirmed, 0) as model_count_fulfillment_confirmed, | ||
coalesce(source_metrics.count_fulfillment_confirmed, 0) as source_count_fulfillment_confirmed, | ||
coalesce(model_metrics.count_fulfillment_delivered, 0) as model_count_fulfillment_delivered, | ||
coalesce(source_metrics.count_fulfillment_delivered, 0) as source_count_fulfillment_delivered | ||
|
||
from model_metrics | ||
full outer join source_metrics | ||
on model_metrics.source_relation = source_metrics.source_relation | ||
and model_metrics.shop_id = source_metrics.shop_id | ||
and model_metrics.date_day = source_metrics.date_day | ||
) | ||
|
||
select * | ||
from final | ||
where | ||
model_count_fulfillment_delayed != source_count_fulfillment_delayed or | ||
model_count_fulfillment_in_transit != source_count_fulfillment_in_transit or | ||
model_count_fulfillment_confirmed != source_count_fulfillment_confirmed or | ||
model_count_fulfillment_delivered != source_count_fulfillment_delivered |
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
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,3 +1,3 @@ | ||
packages: | ||
- package: fivetran/shopify_source | ||
version: [">=0.12.0", "<0.13.0"] | ||
version: [">=0.12.0", "<0.13.0"] |