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

Feature: Union schema compatibility #30

Merged
merged 14 commits into from
Oct 12, 2023
3 changes: 2 additions & 1 deletion .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export CI_SNOWFLAKE_DBT_USER=$(gcloud secrets versions access latest --secret="C
export CI_SNOWFLAKE_DBT_WAREHOUSE=$(gcloud secrets versions access latest --secret="CI_SNOWFLAKE_DBT_WAREHOUSE" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_HOST=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_HOST" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_HTTP_PATH=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_HTTP_PATH" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_TOKEN=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_TOKEN" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_TOKEN=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_TOKEN" --project="dbt-package-testing-363917")
export CI_DATABRICKS_DBT_CATALOG=$(gcloud secrets versions access latest --secret="CI_DATABRICKS_DBT_CATALOG" --project="dbt-package-testing-363917")
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ steps:
- "CI_DATABRICKS_DBT_HOST"
- "CI_DATABRICKS_DBT_HTTP_PATH"
- "CI_DATABRICKS_DBT_TOKEN"
- "CI_DATABRICKS_DBT_CATALOG"
commands: |
bash .buildkite/scripts/run_models.sh databricks
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# dbt_pinterest v0.10.0
[PR #30](https://github.com/fivetran/dbt_pinterest/pull/30) includes the following updates:
## Feature update 🎉
- Unioning capability! This adds the ability to union source data from multiple pinterest connectors. Refer to the [README](https://github.com/fivetran/dbt_pinterest/blob/main/README.md) for more details.
fivetran-catfritz marked this conversation as resolved.
Show resolved Hide resolved

## 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.
- Updated tests to account for the new `source_relation` column.
- The `source_relation` column is included in all joins in the transform package.

# dbt_pinterest v0.9.0

# Pinterest Ads v5 Upgrade
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Include the following pinterest package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/pinterest
version: [">=0.9.0", "<0.10.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=0.10.0", "<0.11.0"] # we recommend using ranges to capture non-breaking changes automatically
```

Do NOT include the `pinterest_source` package in this file. The transformation package itself has a dependency on it and will install the source package as well.
Expand All @@ -77,6 +77,18 @@ vars:
## (Optional) Step 5: Additional configurations
<details><summary>Expand for configurations</summary>

### Union multiple connectors
If you have multiple pinterest 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 `pinterest_ads_union_schemas` OR `pinterest_ads_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

```yml
vars:
pinterest_ads_union_schemas: ['pinterest_usa','pinterest_canada'] # use this if the data is in different schemas/datasets of the same database/project
pinterest_ads_union_databases: ['pinterest_usa','pinterest_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.

### Passing Through Additional Metrics
By default, this package will select `clicks`, `impressions`, and `cost` from the source reporting tables to store into the staging models. If you would like to pass through additional metrics to the staging models, add the below configurations to your `dbt_project.yml` file. These variables allow for the pass-through fields to be aliased (`alias`) if desired, but not required. Use the below format for declaring the respective pass-through variables:

Expand Down Expand Up @@ -135,7 +147,7 @@ This dbt package is dependent on the following dbt packages. Please be aware tha
```yml
packages:
- package: fivetran/pinterest_source
version: [">=0.9.0", "<0.10.0"]
version: [">=0.10.0", "<0.11.0"]

- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
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: 'pinterest'
version: '0.9.0'
version: '0.10.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 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.

14 changes: 7 additions & 7 deletions integration_tests/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ integration_tests:
pass: "{{ env_var('CI_REDSHIFT_DBT_PASS') }}"
dbname: "{{ env_var('CI_REDSHIFT_DBT_DBNAME') }}"
port: 5439
schema: pinterest_integration_tests_3
schema: pinterest_integration_tests_4
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: pinterest_integration_tests_3
schema: pinterest_integration_tests_4
threads: 8
keyfile_json: "{{ env_var('GCLOUD_SERVICE_KEY') | as_native }}"
snowflake:
Expand All @@ -33,7 +33,7 @@ integration_tests:
role: "{{ env_var('CI_SNOWFLAKE_DBT_ROLE') }}"
database: "{{ env_var('CI_SNOWFLAKE_DBT_DATABASE') }}"
warehouse: "{{ env_var('CI_SNOWFLAKE_DBT_WAREHOUSE') }}"
schema: pinterest_integration_tests_3
schema: pinterest_integration_tests_4
threads: 8
postgres:
type: postgres
Expand All @@ -42,13 +42,13 @@ integration_tests:
pass: "{{ env_var('CI_POSTGRES_DBT_PASS') }}"
dbname: "{{ env_var('CI_POSTGRES_DBT_DBNAME') }}"
port: 5432
schema: pinterest_integration_tests_3
schema: pinterest_integration_tests_4
threads: 8
databricks:
catalog: null
catalog: "{{ env_var('CI_DATABRICKS_DBT_CATALOG') }}"
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
http_path: "{{ env_var('CI_DATABRICKS_DBT_HTTP_PATH') }}"
schema: pinterest_integration_tests_3
threads: 2
schema: pinterest_integration_tests_4
threads: 8
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
9 changes: 7 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: 'pinterest_integration_tests'
version: '0.9.0'
version: '0.10.0'
profile: 'integration_tests'
config-version: 2

vars:
pinterest_schema: pinterest_integration_tests_3
pinterest_schema: pinterest_integration_tests_4
pinterest_ad_group_history_identifier: "pinterest_ad_group_history_data"
pinterest_campaign_history_identifier: "pinterest_campaign_history_data"
pinterest_pin_promotion_history_identifier: "pinterest_pin_promotion_history_data"
Expand All @@ -16,6 +16,11 @@ vars:
pinterest_advertiser_history_identifier: "pinterest_advertiser_history_data"
pinterest_advertiser_report_identifier: "pinterest_advertiser_report_data"

models:
pinterest_source:
tmp:
+materialized: table

seeds:
+quote_columns: "{{ true if target.type in ('redshift','postgres') else false }}"
pinterest_integration_tests:
Expand Down
18 changes: 18 additions & 0 deletions models/pinterest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- pin_promotion_id
- ad_group_id
- campaign_id
Expand All @@ -15,6 +16,8 @@ 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: date_day
description: "{{ doc('date_day') }}"
tests:
Expand Down Expand Up @@ -83,11 +86,14 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- ad_group_id
- advertiser_id
- campaign_id
- date_day
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: "{{ doc('date_day') }}"
tests:
Expand Down Expand Up @@ -128,10 +134,13 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- campaign_id
- advertiser_id
- date_day
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: "{{ doc('date_day') }}"
tests:
Expand Down Expand Up @@ -160,9 +169,12 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- advertiser_id
- date_day
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: "{{ doc('date_day') }}"
tests:
Expand All @@ -189,12 +201,15 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- keyword_id
- ad_group_id
- campaign_id
- advertiser_id
- date_day
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: "{{ doc('date_day') }}"
tests:
Expand Down Expand Up @@ -233,12 +248,15 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- pin_promotion_id
- ad_group_id
- campaign_id
- advertiser_id
- date_day
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: "{{ doc('date_day') }}"
tests:
Expand Down
6 changes: 5 additions & 1 deletion models/pinterest_ads__ad_group_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ad_groups as (
fields as (

select
report.source_relation,
report.date_day,
advertisers.advertiser_name,
advertisers.advertiser_id,
Expand All @@ -51,11 +52,14 @@ fields as (
from report
left join ad_groups
on report.ad_group_id = ad_groups.ad_group_id
and report.source_relation = ad_groups.source_relation
left join campaigns
on ad_groups.campaign_id = campaigns.campaign_id
and ad_groups.source_relation = campaigns.source_relation
left join advertisers
on campaigns.advertiser_id = advertisers.advertiser_id
{{ dbt_utils.group_by(12) }}
and campaigns.source_relation = advertisers.source_relation
{{ dbt_utils.group_by(13) }}
)

select *
Expand Down
4 changes: 3 additions & 1 deletion models/pinterest_ads__advertiser_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ advertisers as (
fields as (

select
report.source_relation,
report.date_day,
advertisers.advertiser_name,
report.advertiser_id,
Expand All @@ -30,7 +31,8 @@ fields as (
from report
left join advertisers
on report.advertiser_id = advertisers.advertiser_id
{{ dbt_utils.group_by(5) }}
and report.source_relation = advertisers.source_relation
{{ dbt_utils.group_by(6) }}
)

select *
Expand Down
5 changes: 4 additions & 1 deletion models/pinterest_ads__campaign_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ advertisers as (
fields as (

select
report.source_relation,
report.date_day,
advertisers.advertiser_name,
advertisers.advertiser_id,
Expand All @@ -36,9 +37,11 @@ fields as (
from report
left join campaigns
on report.campaign_id = campaigns.campaign_id
and report.source_relation = campaigns.source_relation
left join advertisers
on campaigns.advertiser_id = advertisers.advertiser_id
{{ dbt_utils.group_by(6) }}
and campaigns.source_relation = advertisers.source_relation
{{ dbt_utils.group_by(7) }}
)

select *
Expand Down
7 changes: 6 additions & 1 deletion models/pinterest_ads__keyword_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ keywords as (
fields as (

select
report.source_relation,
report.date_day,
advertisers.advertiser_name,
advertisers.advertiser_id,
Expand All @@ -57,13 +58,17 @@ fields as (
from report
left join keywords
on report.keyword_id = keywords.keyword_id
and report.source_relation = keywords.source_relation
left join ad_groups
on keywords.ad_group_id = ad_groups.ad_group_id
and keywords.source_relation = ad_groups.source_relation
left join campaigns
on ad_groups.campaign_id = campaigns.campaign_id
and ad_groups.source_relation = campaigns.source_relation
left join advertisers
on campaigns.advertiser_id = advertisers.advertiser_id
{{ dbt_utils.group_by(11) }}
and campaigns.source_relation = advertisers.source_relation
{{ dbt_utils.group_by(12) }}
)

select *
Expand Down
7 changes: 6 additions & 1 deletion models/pinterest_ads__pin_promotion_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ advertisers as (
joined as (

select
report.source_relation,
report.date_day,
campaigns.advertiser_id,
advertisers.advertiser_name,
Expand All @@ -61,14 +62,18 @@ joined as (
from report
left join pins
on report.pin_promotion_id = pins.pin_promotion_id
and report.source_relation = pins.source_relation
left join ad_groups
on report.ad_group_id = ad_groups.ad_group_id
and report.source_relation = ad_groups.source_relation
left join campaigns
on report.campaign_id = campaigns.campaign_id
and report.source_relation = campaigns.source_relation
left join advertisers
on campaigns.advertiser_id = advertisers.advertiser_id
and campaigns.source_relation = advertisers.source_relation

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

select *
Expand Down
7 changes: 6 additions & 1 deletion models/pinterest_ads__url_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ advertisers as (
joined as (

select
report.source_relation,
report.date_day,
campaigns.advertiser_id,
advertisers.advertiser_name,
Expand Down Expand Up @@ -68,18 +69,22 @@ joined as (
from report
left join pins
on report.pin_promotion_id = pins.pin_promotion_id
and report.source_relation = pins.source_relation
left join ad_groups
on report.ad_group_id = ad_groups.ad_group_id
and report.source_relation = ad_groups.source_relation
left join campaigns
on report.campaign_id = campaigns.campaign_id
and report.source_relation = campaigns.source_relation
left join advertisers
on campaigns.advertiser_id = advertisers.advertiser_id
and campaigns.source_relation = advertisers.source_relation

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

{{ dbt_utils.group_by(22) }}
{{ dbt_utils.group_by(23) }}
)

select *
Expand Down
7 changes: 5 additions & 2 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
packages:
- package: fivetran/pinterest_source
version: [">=0.9.0", "<0.10.0"]
# - package: fivetran/pinterest_source
# version: [">=0.10.0", "<0.11.0"]
- git: https://github.com/fivetran/dbt_pinterest_source.git
revision: MagicBot/add-union-schema
warn-unpinned: false
fivetran-catfritz marked this conversation as resolved.
Show resolved Hide resolved