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

bug/renamed-columns-datespine #56

Merged
merged 4 commits into from
Jul 24, 2024
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# dbt_salesforce v1.1.1
[PR #56](https://github.com/fivetran/dbt_salesforce/pull/56) includes the following updates:
## Bugfix
- Updated the logic for model `int_salesforce__date_spine` to reference the `stg_*` staging models instead of the source tables.
- This was necessary since the staging models account for multiple spellings of column names while the source tables do not.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also add either another bullet here or an under the hood entry that now that model has a depends on statement and also leverages the flags.WHICH. More for our purposes so we know how this issue was addressed and some underlying impacts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!


## Under the hood
- Added `--depends_on:` comments to `int_salesforce__date_spine` to prevent errors during `dbt run`.
- Added `flags.WHICH in ('run', 'build')` as a condition in `int_salesforce__date_spine` to prevent call statements from querying the staging models during a `dbt compile`.

# dbt_salesforce v1.1.0
[PR #55](https://github.com/fivetran/dbt_salesforce/pull/55) includes the following updates:

Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 2
name: 'salesforce'
version: '1.1.0'
version: '1.1.1'
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
salesforce:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/run_results.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'salesforce_integration_tests'
version: '1.1.0'
version: '1.1.1'
config-version: 2

profile: 'integration_tests'
Expand Down
31 changes: 20 additions & 11 deletions models/salesforce/intermediate/int_salesforce__date_spine.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{% if var('salesforce__lead_enabled', True) -%}
-- depends_on: {{ var('lead') }}
{% else -%}
-- depends_on: {{ var('opportunity') }}
{% endif %}
Comment on lines +1 to +5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is still necessary for dbt run. I tried running without it, and the error said to put it back. It's still not necessary for compilation, however.

with spine as (

{% if execute %}
{% if execute and flags.WHICH in ('run', 'build') %}

{%- set first_date_query %}
select
Expand All @@ -9,36 +14,40 @@ with spine as (
cast({{ dbt.dateadd("month", -1, "current_date") }} as date)
) as min_date
{% if var('salesforce__lead_enabled', True) %}
from {{ source('salesforce', 'lead') }}
from {{ var('lead') }}
{% else %}
from {{ source('salesforce', 'opportunity') }}
from {{ var('opportunity') }}
{% endif %}
{% endset -%}

{%- set first_date = dbt_utils.get_single_value(first_date_query) %}

{% 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) %}
from {{ source('salesforce', 'lead') }}
from {{ var('lead') }}
{% else %}
from {{ source('salesforce', 'opportunity') }}
from {{ var('opportunity') }}
{% endif %}
{% endset -%}

{%- set last_date = dbt_utils.get_single_value(last_date_query) %}

{% else %}

{% set first_date = 'dbt.dateadd("month", -1, "current_date")' %}
{% set last_date = 'dbt.current_timestamp_backcompat()' %}
{%- set first_date_query%}
select cast({{ dbt.dateadd("month", -1, "current_date") }} as date)
{% endset -%}

{% set last_date_query %}
select cast({{ dbt.current_timestamp_backcompat() }} as date)
{% endset -%}

{% endif %}

{%- set first_date = dbt_utils.get_single_value(first_date_query) %}
{%- set last_date = dbt_utils.get_single_value(last_date_query) %}

{{ dbt_utils.date_spine(
datepart="day",
start_date="cast('" ~ first_date ~ "' as date)",
Expand Down