Skip to content

Commit 9f55a85

Browse files
fivetran-data-model-botfivetran-joemarkiewiczfivetran-catfritzgithub-actions[bot]
authored
Standardize unioning macros to use fivetran_utils versions (#19)
* MagicBot/standardize-unioning-macros * fix base * yml * Generate dbt docs via GitHub Actions * update packages.yml dependency --------- Co-authored-by: Joe Markiewicz <74217849+fivetran-joemarkiewicz@users.noreply.github.com> Co-authored-by: Catherine Fritz <111930712+fivetran-catfritz@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 2bb0625 commit 9f55a85

28 files changed

Lines changed: 244 additions & 344 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# dbt
2+
worktrees/
23
**/package-lock.yml
34
package-lock.yml
45
.dbt/

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# dbt_salesforce_marketing_cloud v0.6.0
2+
3+
[PR #19](https://github.com/fivetran/dbt_salesforce_marketing_cloud/pull/19) includes the following updates:
4+
5+
## Schema/Data Changes (--full-refresh required after upgrading)
6+
**1 total change • 1 possible breaking change**
7+
8+
| Data Model(s) | Change type | Old | New | Notes |
9+
| ------------- | ----------- | --- | --- | ----- |
10+
| All models | `source_relation` column (when using a single Salesforce Marketing Cloud schema) | Empty string (`''`) | `<database>.<schema>` | |
11+
12+
## Feature Updates
13+
- Introduces the new (recommended) `salesforce_marketing_cloud_sources` variable for more robust union data configuration. The old `salesforce_marketing_cloud_union_schemas` and `salesforce_marketing_cloud_union_databases` variables will still be supported. See the [README](https://github.com/fivetran/dbt_salesforce_marketing_cloud/tree/main#define-database-and-schema-variables) for specific details.
14+
15+
## Under the Hood
16+
- Adds the `fivetran_using_source_casing` variable for case-sensitive destination support. When enabled, downstream transformations respect source casing to ensure consistent results. See the [Additional Configurations](https://github.com/fivetran/dbt_salesforce_marketing_cloud/#source-casing-for-case-sensitive-destinations) section of the README for details.
17+
- Introduces `fivetran_utils.partition_by_source_relation` to conditionally include `source_relation` in partition clauses only when multiple sources are configured.
18+
119
# dbt_salesforce_marketing_cloud v0.5.1
220

321
[PR #16](https://github.com/fivetran/dbt_salesforce_marketing_cloud/pull/16) includes the following updates:

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Include the following Salesforce Marketing Cloud package version in your `packag
7575
```yml
7676
packages:
7777
- package: fivetran/salesforce_marketing_cloud
78-
version: [">=0.5.0", "<0.6.0"] # we recommend using ranges to capture non-breaking changes automatically
78+
version: [">=0.6.0", "<0.7.0"] # we recommend using ranges to capture non-breaking changes automatically
7979
```
8080
8181
#### Databricks dispatch configuration
@@ -87,26 +87,40 @@ dispatch:
8787
```
8888

8989
### Define database and schema variables
90-
#### Single connection
90+
#### Option A: Single connection
9191
By default, this package runs using your destination and the `salesforce_marketing_cloud` schema. If this is not where your Salesforce Marketing Cloud data is (for example, if your Salesforce Marketing Cloud schema is named `salesforce_marketing_cloud_fivetran`), add the following configuration to your root `dbt_project.yml` file:
9292

9393
```yml
9494
vars:
95-
salesforce_marketing_cloud_database: your_database_name
95+
salesforce_marketing_cloud_database: your_destination_name
9696
salesforce_marketing_cloud_schema: your_schema_name
9797
```
98-
#### Union multiple connections
99-
If you have multiple Salesforce Marketing Cloud connections in Fivetran and would like to use this package on all of them simultaneously, we have provided functionality to do so. The package will union all of the data together and pass the unioned table into the transformations. You will be able to see which source it came from in the `source_relation` column of each model. To use this functionality, you will need to set either the `salesforce_marketing_cloud_union_schemas` OR `salesforce_marketing_cloud_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:
98+
99+
#### Option B: Union multiple connections
100+
If you have multiple Salesforce Marketing Cloud connections in Fivetran and would like to use this package on all of them simultaneously, we have provided functionality to do so. For each source table, the package will union all of the data together and pass the unioned table into the transformations. The `source_relation` column in each model indicates the origin of each record.
101+
102+
To use this functionality, you will need to set the `salesforce_marketing_cloud_sources` variable in your root `dbt_project.yml` file:
100103

101104
```yml
105+
# dbt_project.yml
106+
102107
vars:
103-
salesforce_marketing_cloud_union_schemas: ['sfmc_usa','sfmc_canada'] # use this if the data is in different schemas/datasets of the same database/project
104-
salesforce_marketing_cloud_union_databases: ['sfmc_usa','sfmc_canada'] # use this if the data is in different databases/projects but uses the same schema name
108+
salesforce_marketing_cloud:
109+
salesforce_marketing_cloud_sources:
110+
- database: connection_1_destination_name # Required
111+
schema: connection_1_schema_name # Required
112+
name: connection_1_source_name # Required only if following the step in the following subsection
113+
114+
- database: connection_2_destination_name
115+
schema: connection_2_schema_name
116+
name: connection_2_source_name
105117
```
106118

107-
> NOTE: The native `source.yml` connection set up in the package will not function when the union schema/database feature is utilized. Although the data will be correctly combined, you will not observe the sources linked to the package models in the Directed Acyclic Graph (DAG). This happens because the package includes only one defined `source.yml`.
119+
> Previous versions of this package employed two separate, mutually exclusive variables for unioning: `salesforce_marketing_cloud_union_schemas` and `salesforce_marketing_cloud_union_databases`. While these variables are still supported, `salesforce_marketing_cloud_sources` is the recommended variable to configure.
120+
121+
#### Optional: Incorporate unioned sources into DAG
108122

109-
To connect your multiple schema/database sources to the package models, follow the steps outlined in the [Union Data Defined Sources Configuration](https://github.com/fivetran/dbt_fivetran_utils/tree/releases/v0.4.latest#union_data-source) section of the Fivetran Utils documentation for the union_data macro. This will ensure a proper configuration and correct visualization of connections in the DAG.
123+
If you use [Fivetran Transformations for dbt Core™](https://fivetran.com/docs/transformations/dbt#transformationsfordbtcore) and are unioning multiple Salesforce Marketing Cloud connections, you can define your sources in a property `.yml` file, [using this as a template](https://github.com/fivetran/dbt_salesforce_marketing_cloud/blob/main/models/staging/src_salesforce_marketing_cloud.yml). Set the variable `has_defined_sources: true` under the Salesforce Marketing Cloud namespace in your `dbt_project.yml`. Otherwise, your Salesforce Marketing Cloud connections won't appear in your DAG. See the `union_connections` macro [documentation](https://github.com/fivetran/dbt_fivetran_utils/tree/releases/v0.4.latest#optional-union-connections-defined-sources-configuration) for full configuration details.
110124

111125
### Enable/Disable Variables
112126
By default, this package brings in data from the Salesforce Marketing Cloud `link` and `list` source tables. However, if you have disabled syncing these sources, you will need to add the following configuration to your `dbt_project.yml`:
@@ -141,6 +155,14 @@ vars:
141155
salesforce_marketing_cloud_<default_source_table_name>_identifier: your_table_name
142156
```
143157

158+
#### Source casing for case-sensitive destinations
159+
By default, the package applies case-insensitive comparisons when resolving `source_relation` values. If your destination is case-sensitive and you want downstream transformations to respect the exact casing of your source database and schema names, set the following variable:
160+
161+
```yml
162+
vars:
163+
fivetran_using_source_casing: true
164+
```
165+
144166
### (Optional) Orchestrate your models with Fivetran Transformations for dbt Core™
145167
<details><summary>Expand for details</summary>
146168
<br>

dbt_project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
config-version: 2
22
name: 'salesforce_marketing_cloud'
3-
version: '0.5.1'
3+
version: '0.6.0'
44
require-dbt-version: [">=1.3.0", "<3.0.0"]
55

66
models:

docs/catalog.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/index.html

Lines changed: 3 additions & 250 deletions
Large diffs are not rendered by default.

docs/manifest.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

integration_tests/ci/test_scenarios.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ test_scenarios:
2121
vars:
2222
salesforce_marketing_cloud__link_enabled: false
2323
salesforce_marketing_cloud__list_enabled: false
24-
include_incremental: true
24+
include_incremental: true
25+
26+
- name: "MDLS"
27+
vars:
28+
fivetran_using_source_casing: true
29+
include_incremental: false
30+
include_dbt_seed: true

integration_tests/dbt_project.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 'salesforce_marketing_cloud_integration_tests'
2-
version: '0.5.1'
2+
version: '0.6.0'
33
config-version: 2
44

55
profile: 'integration_tests'
@@ -25,14 +25,13 @@ models:
2525
+persist_docs:
2626
relation: true
2727
columns: "{{ false if target.type in ('databricks') else true }}"
28-
+schema: "{{ 'sfmc_sqlw_tests' if target.name == 'databricks-sql' else 'salesforce_marketing_cloud' }}"
29-
# +schema: "salesforce_marketing_cloud_{{ var('directed_schema','dev') }}" ## To be used for validation testing
28+
+schema: "salesforce_marketing_cloud_{{ var('directed_schema','dev') }}" ## To be used for validation testing
3029

3130
seeds:
3231
+docs:
3332
show: False
3433
salesforce_marketing_cloud_integration_tests:
35-
+quote_columns: "{{ true if target.type == 'redshift' else false }}"
34+
+quote_columns: "{{ target.type == 'redshift' or var('fivetran_using_source_casing', false) }}"
3635
email_data:
3736
+column_types:
3837
id: "{{ 'string' if target.type in ('bigquery', 'spark', 'databricks') else 'varchar' }}"
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1+
{% if var('salesforce_marketing_cloud_union_schemas', []) | length > 0 or var('salesforce_marketing_cloud_union_databases', []) | length > 0 %}
2+
13
{{
24
fivetran_utils.union_data(
3-
table_identifier='email',
4-
database_variable='salesforce_marketing_cloud_database',
5-
schema_variable='salesforce_marketing_cloud_schema',
5+
table_identifier='email',
6+
database_variable='salesforce_marketing_cloud_database',
7+
schema_variable='salesforce_marketing_cloud_schema',
68
default_database=target.database,
79
default_schema='salesforce_marketing_cloud',
810
default_variable='email',
911
union_schema_variable='salesforce_marketing_cloud_union_schemas',
1012
union_database_variable='salesforce_marketing_cloud_union_databases'
1113
)
1214
}}
15+
16+
{% else %}
17+
18+
{{
19+
fivetran_utils.union_connections(
20+
connection_dictionary='salesforce_marketing_cloud_sources',
21+
single_source_name='salesforce_marketing_cloud',
22+
single_table_name='email'
23+
)
24+
}}
25+
26+
{% endif %}

0 commit comments

Comments
 (0)