-
Notifications
You must be signed in to change notification settings - Fork 28
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
bug/spine-empty-lead-update #52
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh la la what's this