-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* bug/spine-empty-lead-update * add tests and changelog * regen docs * Update CHANGELOG.md Co-authored-by: Joe Markiewicz <[email protected]> --------- Co-authored-by: Joe Markiewicz <[email protected]>
- Loading branch information
1 parent
abdc7e7
commit 614880a
Showing
12 changed files
with
137 additions
and
90 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
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
32 changes: 32 additions & 0 deletions
32
integration_tests/tests/consistency/consistency_daily_activity.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,32 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
-- this test ensures the daily_activity end model matches the prior version | ||
with prod as ( | ||
select * | ||
from {{ target.schema }}_salesforce_prod.salesforce__daily_activity | ||
), | ||
|
||
dev as ( | ||
select * | ||
from {{ target.schema }}_salesforce_dev.salesforce__daily_activity | ||
), | ||
|
||
final as ( | ||
-- test will fail if any rows from prod are not found in dev | ||
(select * from prod | ||
except distinct | ||
select * from dev) | ||
|
||
union all -- union since we only care if rows are produced | ||
|
||
-- test will fail if any rows from dev are not found in prod | ||
(select * from dev | ||
except distinct | ||
select * from prod) | ||
) | ||
|
||
select * | ||
from final |
21 changes: 21 additions & 0 deletions
21
integration_tests/tests/consistency/consistency_daily_activity_count.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,21 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
-- this test is to make sure the rows counts are the same between versions | ||
with prod as ( | ||
select count(*) as prod_rows | ||
from {{ target.schema }}_salesforce_prod.salesforce__daily_activity | ||
), | ||
|
||
dev as ( | ||
select count(*) as dev_rows | ||
from {{ target.schema }}_salesforce_dev.salesforce__daily_activity | ||
) | ||
|
||
-- test will return values and fail if the row counts don't match | ||
select * | ||
from prod | ||
join dev | ||
on prod.prod_rows != dev.dev_rows |
21 changes: 21 additions & 0 deletions
21
integration_tests/tests/integrity/integrity_daily_activity.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,21 @@ | ||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
-- this test is to make sure there is no fanout between the spine and the daily_activity | ||
with spine as ( | ||
select count(*) as spine_count | ||
from {{ target.schema }}_salesforce_dev.int_salesforce__date_spine | ||
), | ||
|
||
daily_activity as ( | ||
select count(*) as daily_activity_count | ||
from {{ target.schema }}_salesforce_dev.salesforce__daily_activity | ||
) | ||
|
||
-- test will return values and fail if the row counts don't match | ||
select * | ||
from spine | ||
join daily_activity | ||
on spine.spine_count != daily_activity.daily_activity_count |
73 changes: 28 additions & 45 deletions
73
models/salesforce/intermediate/int_salesforce__date_spine.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 |
---|---|---|
@@ -1,68 +1,51 @@ | ||
|
||
with spine as ( | ||
|
||
{% if execute %} | ||
{% set first_date_query %} | ||
{% if var('salesforce__lead_enabled', True) %} | ||
select min( created_date ) as min_date from {{ source('salesforce', 'lead') }} | ||
{% else %} | ||
select coalesce(min( created_date ), '2015-01-01') as min_date from {{ source('salesforce', 'opportunity') }} | ||
{% endif %} | ||
|
||
{% endset %} | ||
{% set first_date = run_query(first_date_query).columns[0][0]|string %} | ||
|
||
{% if target.type == 'postgres' %} | ||
{% set first_date_adjust = "cast('" ~ first_date[0:10] ~ "' as date)" %} | ||
|
||
{%- set first_date_query %} | ||
select | ||
coalesce( | ||
min(cast(created_date as date)), | ||
cast({{ dbt.dateadd("month", -1, "current_date") }} as date) | ||
) as min_date | ||
{% if var('salesforce__lead_enabled', True) %} | ||
from {{ source('salesforce', 'lead') }} | ||
{% else %} | ||
{% set first_date_adjust = "'" ~ first_date[0:10] ~ "'" %} | ||
from {{ source('salesforce', 'opportunity') }} | ||
{% endif %} | ||
{% endset -%} | ||
|
||
{% endif %} | ||
{%- set first_date = dbt_utils.get_single_value(first_date_query) %} | ||
|
||
{% else %} {% set first_date_adjust = "'2015-01-01'" %} | ||
{% endif %} | ||
|
||
{% if execute %} | ||
{% set last_date_query %} | ||
select | ||
coalesce( | ||
greatest(max(cast(created_date as date)), cast(current_date as date)), | ||
cast(current_date as date) | ||
) as max_date | ||
{% if var('salesforce__lead_enabled', True) %} | ||
select max( created_date ) as max_date from {{ source('salesforce', 'lead') }} | ||
from {{ source('salesforce', 'lead') }} | ||
{% else %} | ||
select coalesce(max( created_date ), '2024-01-01') as max_date from {{ source('salesforce', 'opportunity') }} | ||
{% endif %} | ||
|
||
{% endset %} | ||
from {{ source('salesforce', 'opportunity') }} | ||
{% endif %} | ||
{% endset -%} | ||
|
||
{% set current_date_query %} | ||
select current_date | ||
{% endset %} | ||
|
||
{% if run_query(current_date_query).columns[0][0]|string < run_query(last_date_query).columns[0][0]|string %} | ||
|
||
{% set last_date = run_query(last_date_query).columns[0][0]|string %} | ||
|
||
{% else %} {% set last_date = run_query(current_date_query).columns[0][0]|string %} | ||
{% endif %} | ||
|
||
{% if target.type == 'postgres' %} | ||
{% set last_date_adjust = "cast('" ~ last_date[0:10] ~ "' as date)" %} | ||
{%- set last_date = dbt_utils.get_single_value(last_date_query) %} | ||
|
||
{% else %} | ||
{% set last_date_adjust = "'" ~ last_date[0:10] ~ "'" %} | ||
|
||
{% endif %} | ||
{% set first_date = 'dbt.dateadd("month", -1, "current_date")' %} | ||
{% set last_date = 'dbt.current_timestamp_backcompat()' %} | ||
|
||
{% endif %} | ||
|
||
{{ dbt_utils.date_spine( | ||
datepart="day", | ||
start_date=first_date_adjust, | ||
end_date=dbt.dateadd("day", 1, last_date_adjust) | ||
start_date="cast('" ~ first_date ~ "' as date)", | ||
end_date=dbt.dateadd("day", 1, "cast('" ~ last_date ~ "' as date)") | ||
) | ||
}} | ||
) | ||
|
||
select | ||
|
||
distinct(date_day) | ||
|
||
select * | ||
from spine |