Skip to content

Commit

Permalink
bug/renamed-columns-datespine (#56)
Browse files Browse the repository at this point in the history
* bug/renamed-columns-datespine

* typo fix

* regen docs

* update changelog
  • Loading branch information
fivetran-catfritz authored Jul 24, 2024
1 parent e945a33 commit bd88214
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
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.

## 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 %}
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

0 comments on commit bd88214

Please sign in to comment.