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

feat(): add ad_reporting passthrough metrics variable #84

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1ea52b1
feat: added if/for statement to append passthrough metrics
aleix-cd Mar 17, 2023
3d2704d
chore: add ad_reporting__passthrough_metrics var into dbt_project.yml
aleix-cd Mar 17, 2023
136e4ef
chore: use namespace to persist updated values inside the loop
aleix-cd Mar 17, 2023
7f18ce2
chore: add ad_reporting__passthrough_metrics if/for loop into ad_repo…
aleix-cd Mar 17, 2023
37a24de
chore: add if/for loop in the rest of reports
aleix-cd Mar 17, 2023
7e414b1
chore: update changelog
aleix-cd Mar 17, 2023
6324685
chore: update version in both dbt_project.yml files
aleix-cd Mar 17, 2023
90c74c6
Merge remote-tracking branch 'upstream/main' into feat/add-ad_reporti…
aleix-cd Apr 4, 2023
bd5594e
chore: add metric.name to ensure name of metric is leveraged
aleix-cd Apr 4, 2023
3f4d4a3
chore: add report-specific variables
aleix-cd Apr 4, 2023
b70c6f2
chore: update changelog
aleix-cd Apr 4, 2023
025d4db
chore: add variables to specific section in macro
aleix-cd Apr 5, 2023
81789c7
fix: use metric instead of metric.name
aleix-cd Apr 5, 2023
785fe47
chore: use persist_pass_through_columns macro
aleix-cd Apr 6, 2023
bf4461c
chore: treat vars as dicts instead of arrays
aleix-cd Apr 14, 2023
1dc9c97
chore: get rid of vars in dbt_project
aleix-cd Apr 14, 2023
302e0c6
fix: access the array of dicts correctly, and then iterate
aleix-cd Apr 27, 2023
f16d8bf
fix: requested changes/fixes in PR review
aleix-cd May 3, 2023
bd3df6e
chore: get rid of comment
aleix-cd May 3, 2023
bd69f46
minor adjustments after further testing
fivetran-joemarkiewicz May 4, 2023
2df1b80
documentation and docs regen updates
fivetran-joemarkiewicz May 8, 2023
7143723
Merge branch 'main' into feat/add-ad_reporting__passthrough_metrics-var
fivetran-joemarkiewicz May 8, 2023
d2ddc72
CHANGELOG reformat
fivetran-joemarkiewicz May 8, 2023
1c72f89
minor adjustments to documentation
fivetran-joemarkiewicz May 8, 2023
d2cd885
version bump
fivetran-joemarkiewicz May 8, 2023
8bbbd97
readme edits
fivetran-joemarkiewicz May 16, 2023
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# dbt_ad_reporting v1.2.2

## Feature Enhancement
- Added `ad_reporting__passthrough_metrics` variable to easily add common metrics across all platforms into the `ad_reporting` models.

## Contributors
- [@aleix-cd](https://github.com/aleix-cd)


# dbt_ad_reporting v1.2.1

## Updates
Expand Down
7 changes: 5 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'ad_reporting'
version: '1.2.1'
version: '1.2.2'

config-version: 2

Expand All @@ -11,4 +11,7 @@ models:
+schema: ad_reporting
intermediate:
+materialized: ephemeral
+schema: int_ad_reporting
+schema: int_ad_reporting

vars:
ad_reporting__passthrough_metrics: []
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: 'ad_reporting_integration_tests'
version: '1.2.1'
version: '1.2.2'
profile: 'integration_tests'
config-version: 2

Expand Down
9 changes: 8 additions & 1 deletion macros/get_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

{#- Add the consistent_fields and account_fields to all reports regardless of type -#}
{%- if report_type -%}
{%- if var('ad_reporting__passthrough_metrics') -%}
{%- set ns = namespace(consistent_fields=consistent_fields) -%}
{%- for field in var('ad_reporting__passthrough_metrics') -%}
{%- set ns.consistent_fields = ns.consistent_fields + [field] -%}
{% endfor %}
{%- set consistent_fields = ns.consistent_fields -%}
{%- endif -%}
{%- for consistent_field in consistent_fields -%}
{%- do final_fields_superset.update({consistent_field: consistent_field}) -%}
{%- endfor -%}
Expand Down Expand Up @@ -78,7 +85,7 @@ select
cast( '{{ platform }}' as {{ dbt.type_string() }}) as platform,

{% for field in final_fields_superset.keys()|sort() -%}
{% if field in ['clicks', 'impressions'] -%}
{% if field in consistent_fields and field != 'spend' -%}
cast({{ final_fields_superset[field] }} as {{ dbt.type_int() }}) as {{ field }}

{% elif field == 'spend' -%}
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__account_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(4) }}
)
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__ad_group_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
aleix-cd marked this conversation as resolved.
Show resolved Hide resolved
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(8) }}
)
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__ad_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(10) }}
)
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__campaign_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(6) }}
)
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__keyword_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(11) }}
)
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__search_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(12) }}
)
Expand Down
7 changes: 7 additions & 0 deletions models/ad_reporting__url_report.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ aggregated as (
sum(clicks) as clicks,
sum(impressions) as impressions,
sum(spend) as spend

{%- if var('ad_reporting__passthrough_metrics') -%}
{% for metric in var('ad_reporting__passthrough_metrics') %}
, sum({{ metric }}) as {{ metric }}
{% endfor %}
{%- endif -%}

from base
{{ dbt_utils.group_by(16) }}
)
Expand Down