Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# dbt_reddit_ads v1.5.0

[PR #37](https://github.com/fivetran/dbt_reddit_ads/pull/37) includes the following updates:

## Schema/Data Changes (--full-refresh required after upgrading)
**1 total change • 1 possible breaking change**

| Data Model(s) | Change type | Old | New | Notes |
| ------------- | ----------- | --- | --- | ----- |
| All models | `source_relation` column (when using a single reddit_ads schema) | Empty string (`''`) | `<database>.<schema>` | |

## Feature Updates
- Introduces the new (recommended) `reddit_ads_sources` variable for more robust union data configuration. The old `reddit_ads_union_schemas` and `reddit_ads_union_databases` variables will still be supported. See the [README](https://github.com/fivetran/dbt_reddit_ads/tree/main#define-database-and-schema-variables) for specific details.

## Under the Hood
- 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_reddit_ads/#source-casing-for-case-sensitive-destinations) section of the README for details.
- Introduces `fivetran_utils.partition_by_source_relation` to conditionally include `source_relation` in partition clauses only when multiple sources are configured.

# dbt_reddit_ads v1.4.0

[PR #33](https://github.com/fivetran/dbt_reddit_ads/pull/33) includes the following updates:
Expand Down
51 changes: 37 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ If you are not using the downstream [Ad Reporting](https://github.com/fivetran/d
```yaml
packages:
- package: fivetran/reddit_ads
version: [">=1.4.0", "<1.5.0"]
version: [">=1.5.0", "<1.6.0"]
```

> All required sources and staging models are now bundled into this transformation package. Do not include `fivetran/reddit_ads_source` in your `packages.yml` since this package has been deprecated.
Expand All @@ -88,14 +88,41 @@ dispatch:
```

### Define database and schema variables
#### Option A: Single connection
By default, this package runs using your destination and the `reddit_ads` schema. If this is not where your Reddit Ads data is (for example, if your Reddit Ads schema is named `reddit_ads_fivetran`), add the following configuration to your root `dbt_project.yml` file:

```yml
vars:
reddit_ads_database: your_destination_name
reddit_ads_schema: your_schema_name
reddit_ads_schema: your_schema_name
```

#### Option B: Union multiple connections
If you have multiple Reddit Ads 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.

To use this functionality, you will need to set the `reddit_ads_sources` variable in your root `dbt_project.yml` file:

```yml
# dbt_project.yml

vars:
reddit_ads:
reddit_ads_sources:
- database: connection_1_destination_name # Required
schema: connection_1_schema_name # Required
name: connection_1_source_name # Required only if following the step in the following subsection

- database: connection_2_destination_name
schema: connection_2_schema_name
name: connection_2_source_name
```

> Previous versions of this package employed two separate, mutually exclusive variables for unioning: `reddit_ads_union_schemas` and `reddit_ads_union_databases`. While these variables are still supported, `reddit_ads_sources` is the recommended variable to configure.

#### Optional: Incorporate unioned sources into DAG

If you use [Fivetran Transformations for dbt Core™](https://fivetran.com/docs/transformations/dbt#transformationsfordbtcore) and are unioning multiple Reddit Ads connections, you can define your sources in a property `.yml` file, [using this as a template](https://github.com/fivetran/dbt_reddit_ads/blob/main/models/staging/src_reddit_ads.yml). Set the variable `has_defined_sources: true` under the Reddit Ads namespace in your `dbt_project.yml`. Otherwise, your Reddit Ads 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.

### Enable/disable models and sources
Your Reddit Ads connection may not sync every table that this package expects. If you do not have the `BUSINESS_ACCOUNT`, `CAMPAIGN_COUNTRY_REPORT` or `CAMPAIGN_COUNTRY_CONVERSIONS_REPORT` tables synced, add the corresponding following variable to your root `dbt_project.yml` file. Note that if `BUSINESS_ACCOUNT` is not available, setting the variable to false will fall back to using the `ACCOUNT` table instead.

Expand All @@ -109,18 +136,6 @@ vars:
### (Optional) Additional configurations
<details open><summary>Expand/Collapse details</summary>

#### Union multiple connections
If you have multiple reddit_ads 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 `reddit_ads_union_schemas` OR `reddit_ads_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

```yml
vars:
reddit_ads_union_schemas: ['reddit_ads_usa','reddit_ads_canada'] # use this if the data is in different schemas/datasets of the same database/project
reddit_ads_union_databases: ['reddit_ads_usa','reddit_ads_canada'] # use this if the data is in different databases/projects but uses the same schema name
```
> 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`.

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.

#### Configure Conversion Event Types
By default, this package considers `purchase`, `lead`, and `custom` events from the `*_conversions_report` source tables to be conversions. This means that the package will only report values for conversion metrics (`conversions`, `total_items`, `total_value`, and `view_through_conversions`) for these 3 event types.

Expand Down Expand Up @@ -207,6 +222,14 @@ vars:
reddit_ads_<default_source_table_name>_identifier: your_table_name
```

#### Source casing for case-sensitive destinations
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:

```yml
vars:
fivetran_using_source_casing: true
```

</details>

### (Optional) Orchestrate your models with Fivetran Transformations for dbt Core™
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: 'reddit_ads'
version: '1.4.0'
version: '1.5.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<3.0.0"]

Expand Down
8 changes: 7 additions & 1 deletion integration_tests/ci/test_scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ test_scenarios:
- name: "country conversions disabled"
vars:
reddit_ads__using_campaign_country_conversions_report: false
include_incremental: false
include_incremental: false

- name: "MDLS"
vars:
fivetran_using_source_casing: true
include_incremental: false
include_dbt_seed: true
5 changes: 3 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'reddit_ads_integration_tests'
version: '1.4.0'
version: '1.5.0'
profile: 'integration_tests'
config-version: 2

Expand Down Expand Up @@ -72,6 +72,7 @@ models:
seeds:
+docs:
show: false
+quote_columns: "{{ target.type == 'redshift' or var('fivetran_using_source_casing', false) }}"
reddit_ads_integration_tests:
reddit_ads_account_conversions:
+column_types:
Expand Down Expand Up @@ -139,4 +140,4 @@ seeds:
campaign_id: "{{ 'string' if target.type in ['bigquery','spark','databricks'] else 'varchar(255)' }}"
flags:
send_anonymous_usage_stats: False
use_colors: True
use_colors: True
10 changes: 5 additions & 5 deletions models/staging/src_reddit_ads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sources:

config:
loaded_at_field: _fivetran_synced
enabled: "{{ var('ad_reporting__reddit_ads_enabled', true) }}"
enabled: "{{ var('ad_reporting__reddit_ads_enabled', true) and var('reddit_ads_sources', []) == [] }}"
freshness:
warn_after: {count: 48, period: hour}
error_after: {count: 168, period: hour}
Expand All @@ -19,7 +19,7 @@ sources:
identifier: "{{ var('reddit_ads_account_identifier', 'account') }}"
description: Each record represents information about an account.
config:
enabled: "{{ (not var('reddit_ads__using_business_account', True) and var('ad_reporting__reddit_ads_enabled', True)) }}"
enabled: "{{ (not var('reddit_ads__using_business_account', True) and var('ad_reporting__reddit_ads_enabled', True)) and var('reddit_ads_sources', []) == [] }}"
columns:
- name: id
description: '{{ doc("account_id") }}'
Expand All @@ -40,7 +40,7 @@ sources:
identifier: "{{ var('reddit_ads_business_account_identifier', 'business_account') }}"
description: Each record represents information about an account.
config:
enabled: "{{ (var('reddit_ads__using_business_account', True) and var('ad_reporting__reddit_ads_enabled', True)) }}"
enabled: "{{ (var('reddit_ads__using_business_account', True) and var('ad_reporting__reddit_ads_enabled', True)) and var('reddit_ads_sources', []) == [] }}"
columns:
- name: id
description: '{{ doc("account_id") }}'
Expand Down Expand Up @@ -484,7 +484,7 @@ sources:
identifier: '{{ var("reddit_ads_campaign_country_report_identifier", "campaign_country_report") }}'
description: '{{ doc("campaign_country_report") }}'
config:
enabled: "{{ var('ad_reporting__reddit_ads_enabled', True) and var('reddit_ads__using_campaign_country_report', True) }}"
enabled: "{{ var('ad_reporting__reddit_ads_enabled', True) and var('reddit_ads__using_campaign_country_report', True) and var('reddit_ads_sources', []) == [] }}"
columns:
- name: account_id
description: '{{ doc("account_id") }}'
Expand All @@ -509,7 +509,7 @@ sources:
identifier: '{{ var("reddit_ads_campaign_country_conversions_report_identifier", "campaign_country_conversions_report") }}'
description: '{{ doc("campaign_country_conversions_report") }}'
config:
enabled: "{{ var('ad_reporting__reddit_ads_enabled', True) and var('reddit_ads__using_campaign_country_report', True) and var('reddit_ads__using_campaign_country_conversions_report', True) }}"
enabled: "{{ var('ad_reporting__reddit_ads_enabled', True) and var('reddit_ads__using_campaign_country_report', True) and var('reddit_ads__using_campaign_country_conversions_report', True) and var('reddit_ads_sources', []) == [] }}"
columns:
- name: account_id
description: '{{ doc("account_id") }}'
Expand Down
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__account.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand All @@ -39,4 +36,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__account_conversions_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
staging_columns=get_account_conversions_report_columns()
)
}}
{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}
from base
),

Expand All @@ -40,4 +37,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__account_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand All @@ -40,4 +37,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__ad.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand All @@ -44,4 +41,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__ad_conversions_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
staging_columns=get_ad_conversions_report_columns()
)
}}
{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}
from base
),

Expand All @@ -41,4 +38,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__ad_group.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand Down Expand Up @@ -47,4 +44,4 @@ final as (
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
staging_columns=get_ad_group_conversions_report_columns()
)
}}
{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}
from base
),

Expand All @@ -41,4 +38,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__ad_group_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand All @@ -41,4 +38,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__ad_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand All @@ -41,4 +38,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_reddit_ads__campaign.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='reddit_ads_union_schemas',
union_database_variable='reddit_ads_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='reddit_ads') }}

from base
),
Expand All @@ -40,4 +37,4 @@ final as (
)

select *
from final
from final
Loading
Loading