Skip to content

Commit

Permalink
Merge pull request #32 from fivetran/MagicBot/add-union-schema
Browse files Browse the repository at this point in the history
Feature: Union schema compatibility
  • Loading branch information
fivetran-catfritz authored Oct 12, 2023
2 parents 230f729 + 9cbfe7a commit be190af
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 25 deletions.
35 changes: 31 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
# dbt_linkedin v0.UPDATE.UPDATE

## Under the Hood:

# dbt_linkedin v0.8.0
[PR #32](https://github.com/fivetran/dbt_linkedin/pull/32) includes the following updates:

## Breaking changes
- Updated materializations of [dbt_linkedin_source](https://github.com/fivetran/dbt_linkedin_source/blob/main/CHANGELOG.md) non-`tmp` staging models from views to tables. This is to bring the materializations into alignment with other ad reporting packages and eliminate errors in Redshift.
- Updated the name of the source created by `dbt_linkedin_source` from `linkedin` to `linkedin_ads`. This was to bring the naming used in this package in alignment with our other ad packages and for compatibility with the union schema feature.
- ❗ If you are using this source, you will need to update the name.
- Updated the following identifiers for consistency with the source name and compatibility with the union schema feature:

| current | previous |
|----------|----------|
| linkedin_ads_account_history_identifier | linkedin_account_history_identifier
| linkedin_ads_ad_analytics_by_creative_identifier | linkedin_ad_analytics_by_creative_identifier
| linkedin_ads_campaign_group_history_identifier | linkedin_campaign_group_history_identifier
| linkedin_ads_campaign_history_identifier | linkedin_campaign_history_identifier
| linkedin_ads_creative_history_identifier | linkedin_creative_history_identifier
| linkedin_ads_ad_analytics_by_campaign_identifier | linkedin_ad_analytics_by_campaign_identifier

- If you are using the previous identifier, be sure to update to the current version!

## Feature update 🎉
- Unioning capability! This adds the ability to union source data from multiple linkedin connectors. Refer to the [Union Multiple Connectors README section](https://github.com/fivetran/dbt_linkedin/blob/main/README.md#union-multiple-connectors) for more details.

## Under the hood 🚘
- In the source package, updated tmp models to union source data using the `fivetran_utils.union_data` macro.
- To distinguish which source each field comes from, added `source_relation` column in each staging and downstream model and applied the `fivetran_utils.source_relation` macro.
- The `source_relation` column is included in all joins in the transform package.
- Updated tests to account for the new `source_relation` column.

[PR #29](https://github.com/fivetran/dbt_linkedin/pull/329) includes the following updates:
- Incorporated the new `fivetran_utils.drop_schemas_automation` macro into the end of each Buildkite integration test job.
- Updated the pull request [templates](/.github).

# dbt_linkedin v0.7.0
## 🚨 Breaking Changes 🚨
Due to Linkedin Ads API [change in January 2023](https://learn.microsoft.com/en-us/linkedin/marketing/integrations/recent-changes?view=li-lms-2022-12#january-2023), there have been updates in the Linkedin Ads Fivetran Connector and therefore, updates to this Linkedin package.
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Include the following Linkedin Ads package version in your `packages.yml` file:
# packages.yml
packages:
- package: fivetran/linkedin
version: [">=0.7.0", "<0.8.0"]
version: [">=0.8.0", "<0.9.0"]
```
Do **NOT** include the `linkedin_source` package in this file. The transformation package itself has a dependency on it and will install the source package as well.

Expand All @@ -70,7 +70,17 @@ vars:
```

## (Optional) Step 4: Additional configurations
<details><summary>Expand for configurations</summary>
### Union multiple connectors
If you have multiple linkedin connectors 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 `linkedin_ads_union_schemas` OR `linkedin_ads_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

```yml
vars:
linkedin_ads_union_schemas: ['linkedin_usa','linkedin_canada'] # use this if the data is in different schemas/datasets of the same database/project
linkedin_ads_union_databases: ['linkedin_usa','linkedin_canada'] # use this if the data is in different databases/projects but uses the same schema name
```
Please be aware that 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`.

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.

### Switching to Local Currency
Additionally, the package allows you to select whether you want to add in costs in USD or the local currency of the ad. By default, the package uses USD. If you would like to have costs in the local currency, add the following variable to your `dbt_project.yml` file:
Expand Down Expand Up @@ -122,8 +132,6 @@ vars:
linkedin_ads_<default_source_table_name>_identifier: your_table_name
```

</details>

## (Optional) Step 5: Orchestrate your models with Fivetran Transformations for dbt Core™
<details><summary>Expand for more details</summary>

Expand All @@ -137,7 +145,7 @@ This dbt package is dependent on the following dbt packages. Please be aware tha
```yml
packages:
- package: fivetran/linkedin_source
version: [">=0.7.0", "<0.8.0"]
version: [">=0.8.0", "<0.9.0"]
- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
- package: dbt-labs/dbt_utils
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'linkedin'
version: '0.7.0'
version: '0.8.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
vars:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/index.html

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/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ integration_tests:
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
http_path: "{{ env_var('CI_DATABRICKS_DBT_HTTP_PATH') }}"
schema: linkedin_integration_tests_4
threads: 2
threads: 8
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
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: 'linkedin_integration_tests'
version: '0.7.0'
version: '0.8.0'
profile: 'integration_tests'
config-version: 2

Expand Down
2 changes: 2 additions & 0 deletions integration_tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ dbt-postgres>=1.3.0,<2.0.0
dbt-spark>=1.3.0,<2.0.0
dbt-spark[PyHive]>=1.3.0,<2.0.0
dbt-databricks>=1.3.0,<2.0.0

oscrypto @ git+https://github.com/wbond/oscrypto.git@d5f3437
20 changes: 20 additions & 0 deletions models/linkedin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"

- name: account_name
description: A label for the account.

Expand Down Expand Up @@ -62,11 +66,15 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- campaign_id
- account_id
- campaign_group_id
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"

- name: account_name
description: A label for the account.

Expand Down Expand Up @@ -213,10 +221,14 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- campaign_group_id
- account_id
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"

- name: account_name
description: A label for the account.

Expand Down Expand Up @@ -279,12 +291,16 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- creative_id
- campaign_id
- campaign_group_id
- account_id
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"

- name: account_name
description: A label for the account.

Expand Down Expand Up @@ -372,6 +388,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- creative_id
- campaign_id
Expand All @@ -381,6 +398,9 @@ models:
# Below is so we don't run this test if the user has allowed urls to have null entries
enabled: "{{ var('ad_reporting__url_report__using_null_filter', true) }}"
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"

- name: account_name
description: A label for the account.

Expand Down
5 changes: 4 additions & 1 deletion models/linkedin_ads__account_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ report as (
final as (

select
report.source_relation,
report.date_day,
account.account_id,
account.account_name,
Expand All @@ -41,10 +42,12 @@ final as (
from report
left join campaign
on report.campaign_id = campaign.campaign_id
and report.source_relation = campaign.source_relation
left join account
on campaign.account_id = account.account_id
and campaign.source_relation = account.source_relation

{{ dbt_utils.group_by(n=9) }}
{{ dbt_utils.group_by(10) }}

)

Expand Down
6 changes: 5 additions & 1 deletion models/linkedin_ads__campaign_group_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ report as (
final as (

select
report.source_relation,
report.date_day,
campaign_group.campaign_group_id,
campaign_group.campaign_group_name,
Expand All @@ -51,12 +52,15 @@ final as (
from report
left join campaign
on report.campaign_id = campaign.campaign_id
and report.source_relation = campaign.source_relation
left join campaign_group
on campaign.campaign_group_id = campaign_group.campaign_group_id
and campaign.source_relation = campaign_group.source_relation
left join account
on campaign.account_id = account.account_id
and campaign.source_relation = account.source_relation

{{ dbt_utils.group_by(n=12) }}
{{ dbt_utils.group_by(13) }}

)

Expand Down
6 changes: 5 additions & 1 deletion models/linkedin_ads__campaign_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ report as (
final as (

select
report.source_relation,
report.date_day,
report.campaign_id,
campaign.campaign_name,
Expand Down Expand Up @@ -68,12 +69,15 @@ final as (
from report
left join campaign
on report.campaign_id = campaign.campaign_id
and report.source_relation = campaign.source_relation
left join campaign_group
on campaign.campaign_group_id = campaign_group.campaign_group_id
and campaign.source_relation = campaign_group.source_relation
left join account
on campaign.account_id = account.account_id
and campaign.source_relation = account.source_relation

{{ dbt_utils.group_by(n=29) }}
{{ dbt_utils.group_by(30) }}

)

Expand Down
7 changes: 6 additions & 1 deletion models/linkedin_ads__creative_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ report as (
final as (

select
report.source_relation,
report.date_day,
report.creative_id,
campaign.campaign_id,
Expand All @@ -61,14 +62,18 @@ final as (
from report
left join creative
on report.creative_id = creative.creative_id
and report.source_relation = creative.source_relation
left join campaign
on creative.campaign_id = campaign.campaign_id
and creative.source_relation = campaign.source_relation
left join campaign_group
on campaign.campaign_group_id = campaign_group.campaign_group_id
and campaign.source_relation = campaign_group.source_relation
left join account
on campaign.account_id = account.account_id
and campaign.source_relation = account.source_relation

{{ dbt_utils.group_by(n=15) }}
{{ dbt_utils.group_by(16) }}

)

Expand Down
7 changes: 6 additions & 1 deletion models/linkedin_ads__url_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ report as (
final as (

select
report.source_relation,
report.date_day,
creative.click_uri,
creative.base_url,
Expand Down Expand Up @@ -64,18 +65,22 @@ final as (
from report
left join creative
on report.creative_id = creative.creative_id
and report.source_relation = creative.source_relation
left join campaign
on creative.campaign_id = campaign.campaign_id
and creative.source_relation = campaign.source_relation
left join campaign_group
on campaign.campaign_group_id = campaign_group.campaign_group_id
and campaign.source_relation = campaign_group.source_relation
left join account
on campaign.account_id = account.account_id
and campaign.source_relation = account.source_relation

{% if var('ad_reporting__url_report__using_null_filter', True) %}
where creative.click_uri is not null
{% endif %}

{{ dbt_utils.group_by(n=18) }}
{{ dbt_utils.group_by(19) }}

)

Expand Down
2 changes: 1 addition & 1 deletion packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
packages:
- package: fivetran/linkedin_source
version: [">=0.7.0", "<0.8.0"]
version: [">=0.8.0", "<0.9.0"]

0 comments on commit be190af

Please sign in to comment.