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 #28

Merged
merged 14 commits into from
Oct 12, 2023
Merged
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")
3 changes: 2 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ steps:
commands: |
bash .buildkite/scripts/run_models.sh redshift

- label: ":bricks: Run Tests - Databricks"
- label: ":databricks: Run Tests - Databricks"
key: "run_dbt_databricks"
plugins:
- docker#v3.13.0:
Expand All @@ -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
28 changes: 26 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
# dbt_microsoft_ads v0.UPDATE.UPDATE
# dbt_microsoft_ads v0.7.0
[PR #28](https://github.com/fivetran/dbt_microsoft_ads/pull/28) includes the following updates:

## Under the Hood:
## Breaking changes
- Updated the following identifiers for consistency with the source name and compatibility with the union schema feature:

| current | previous |
|----------|----------|
|microsoft_ads_account_performance_daily_report_identifier | microsoft_ads_account_daily_report_identifier |
|microsoft_ads_ad_group_performance_daily_report_identifier | microsoft_ads_ad_group_daily_report_identifier|
|microsoft_ads_ad_performance_daily_report_identifier | microsoft_ads_ad_daily_report_identifier|
|microsoft_ads_campaign_performance_daily_report_identifier | microsoft_ads_campaign_daily_report_identifier|
|microsoft_ads_keyword_performance_daily_report_identifier | microsoft_ads_keyword_daily_report_identifier|
|microsoft_ads_search_query_performance_daily_report_identifier | microsoft_ads_search_query_daily_report_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 microsoft_ads connectors. Refer to the [Union Multiple Connectors README section](https://github.com/fivetran/dbt_microsoft_ads/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 #25](https://github.com/fivetran/dbt_microsoft_ads/pull/25) 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_microsoft_ads v0.6.0

## 🚨 Breaking Changes 🚨:
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Include the following microsoft_ads package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/microsoft_ads
version: [">=0.6.0", "<0.7.0"]
version: [">=0.7.0", "<0.8.0"]
```
## Step 3: Define database and schema variables
By default, this package runs using your destination and the `microsoft_ads` schema. If this is not where your Microsoft Ads data is (for example, if your Microsoft Ads schema is named `microsoft_ads_fivetran`), add the following configuration to your root `dbt_project.yml` file:
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 microsoft_ads 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 `microsoft_ads_union_schemas` OR `microsoft_ads_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

```yml
vars:
microsoft_ads_union_schemas: ['microsoft_ads_usa','microsoft_ads_canada'] # use this if the data is in different schemas/datasets of the same database/project
microsoft_ads_union_databases: ['microsoft_ads_usa','microsoft_ads_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.

### Adding passthrough 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 @@ -126,8 +136,6 @@ vars:
microsoft_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 @@ -142,7 +150,7 @@ This dbt package is dependent on the following dbt packages. Please be aware tha
```yml
packages:
- package: fivetran/microsoft_ads_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"]
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: 'microsoft_ads'
version: '0.6.0'
version: '0.7.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.

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: microsoft_ads_integration_tests_4
schema: microsoft_ads_integration_tests_5
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: microsoft_ads_integration_tests_4
schema: microsoft_ads_integration_tests_5
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: microsoft_ads_integration_tests_4
schema: microsoft_ads_integration_tests_5
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: microsoft_ads_integration_tests_4
schema: microsoft_ads_integration_tests_5
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: microsoft_ads_integration_tests_4
threads: 2
schema: microsoft_ads_integration_tests_5
threads: 8
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
16 changes: 8 additions & 8 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: 'microsoft_ads_integration_tests'
version: '0.6.0'
version: '0.7.0'
profile: 'integration_tests'
config-version: 2

vars:
microsoft_ads_schema: microsoft_ads_integration_tests_4
microsoft_ads_schema: microsoft_ads_integration_tests_5
microsoft_ads_account_history_identifier: "microsoft_ads_account_history_data"
microsoft_ads_account_daily_report_identifier: "microsoft_ads_account_performance_daily_report_data"
microsoft_ads_account_performance_daily_report_identifier: "microsoft_ads_account_performance_daily_report_data"
microsoft_ads_ad_group_history_identifier: "microsoft_ads_ad_group_history_data"
microsoft_ads_ad_group_daily_report_identifier: "microsoft_ads_ad_group_performance_daily_report_data"
microsoft_ads_ad_group_performance_daily_report_identifier: "microsoft_ads_ad_group_performance_daily_report_data"
microsoft_ads_ad_history_identifier: "microsoft_ads_ad_history_data"
microsoft_ads_ad_daily_report_identifier: "microsoft_ads_ad_performance_daily_report_data"
microsoft_ads_ad_performance_daily_report_identifier: "microsoft_ads_ad_performance_daily_report_data"
microsoft_ads_campaign_history_identifier: "microsoft_ads_campaign_history_data"
microsoft_ads_campaign_daily_report_identifier: "microsoft_ads_campaign_performance_daily_report_data"
microsoft_ads_campaign_performance_daily_report_identifier: "microsoft_ads_campaign_performance_daily_report_data"
microsoft_ads_keyword_history_identifier: "microsoft_ads_keyword_history_data"
microsoft_ads_keyword_daily_report_identifier: "microsoft_ads_keyword_performance_daily_report_data"
microsoft_ads_search_daily_report_identifier: "microsoft_ads_search_performance_daily_report_data"
microsoft_ads_keyword_performance_daily_report_identifier: "microsoft_ads_keyword_performance_daily_report_data"
microsoft_ads_search_query_performance_daily_report_identifier: "microsoft_ads_search_performance_daily_report_data"

seeds:
microsoft_ads_integration_tests:
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
21 changes: 21 additions & 0 deletions models/microsoft_ads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- device_os
- device_type
- network
- currency_code
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: '{{ doc("date_day") }}'
- name: account_name
Expand Down Expand Up @@ -47,6 +50,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- campaign_id
Expand All @@ -56,6 +60,8 @@ models:
- network
- currency_code
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: '{{ doc("date_day") }}'
- name: account_name
Expand Down Expand Up @@ -94,6 +100,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- campaign_id
Expand All @@ -105,6 +112,8 @@ models:
- network
- currency_code
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: '{{ doc("date_day") }}'
- name: account_name
Expand Down Expand Up @@ -149,6 +158,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- campaign_id
Expand All @@ -157,6 +167,8 @@ models:
- network
- currency_code
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: '{{ doc("date_day") }}'
- name: account_name
Expand Down Expand Up @@ -198,6 +210,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- campaign_id
Expand All @@ -209,6 +222,8 @@ models:
- network
- currency_code
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: '{{ doc("date_day") }}'
- name: account_name
Expand Down Expand Up @@ -257,6 +272,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- campaign_id
Expand All @@ -269,6 +285,8 @@ models:
- network
- match_type
columns:
- name: source_relation
description: "{{ doc('source_relation') }}"
- name: date_day
description: '{{ doc("date_day") }}'
- name: account_name
Expand Down Expand Up @@ -317,6 +335,7 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- source_relation
- date_day
- account_id
- campaign_id
Expand All @@ -330,6 +349,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") }}'
- name: account_name
Expand Down
12 changes: 7 additions & 5 deletions models/microsoft_ads__account_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ accounts as (
, joined as (

select
date_day,
report.source_relation,
report.date_day,
accounts.account_name,
report.account_id,
accounts.time_zone as account_timezone,
report.device_os,
report.device_type,
report.network,
report.currency_code,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend
sum(report.clicks) as clicks,
sum(report.impressions) as impressions,
sum(report.spend) as spend

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='microsoft_ads__account_passthrough_metrics', transform = 'sum') }}
from report
left join accounts
on report.account_id = accounts.account_id
{{ dbt_utils.group_by(8)}}
and report.source_relation = accounts.source_relation
{{ dbt_utils.group_by(9) }}
)

select *
Expand Down
14 changes: 9 additions & 5 deletions models/microsoft_ads__ad_group_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ accounts as (
joined as (

select
date_day,
report.source_relation,
report.date_day,
accounts.account_name,
report.account_id,
campaigns.campaign_name,
Expand All @@ -42,19 +43,22 @@ joined as (
report.device_type,
report.network,
report.currency_code,
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend
sum(report.clicks) as clicks,
sum(report.impressions) as impressions,
sum(report.spend) as spend

{{ fivetran_utils.persist_pass_through_columns(pass_through_variable='microsoft_ads__ad_group_passthrough_metrics', transform = 'sum') }}
from report
left join accounts
on report.account_id = accounts.account_id
and report.source_relation = accounts.source_relation
left join campaigns
on report.campaign_id = campaigns.campaign_id
and report.source_relation = campaigns.source_relation
left join ad_groups
on report.ad_group_id = ad_groups.ad_group_id
{{ dbt_utils.group_by(11)}}
and report.source_relation = ad_groups.source_relation
{{ dbt_utils.group_by(12) }}
)

select *
Expand Down
Loading