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

pinterest-source-32 #35

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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# dbt_pinterest_source v0.10.2

## Bug Fixes
- Updated the `is_most_recent_record` window function in the following models to exclude the `source_relation` field from the partition statement when `pinterest_ads_union_schemas` or `pinterest_ads_union_databases` variables are empty. Also, modified it to skip the window function if the upstream table is empty, using the new `window_function_if_table_exists()` and `is_table_empty()` macros. This change addresses Redshift's issue with partitioning by constant expressions.
- `stg_pinterest_ads__ad_group_history`
- `stg_pinterest_ads__advertiser_history`
- `stg_pinterest_ads__campaign_history`
- `stg_pinterest_ads__keyword_history`
- `stg_pinterest_ads__pin_promotion_history`

## Contributors
- [@JessicaKMarkiewicz](https://github.com/JessicaKMarkiewicz) ([PR #35](https://github.com/fivetran/dbt_pinterest_source/pull/35))

# dbt_pinterest_source v0.10.1

[PR #31](https://github.com/fivetran/dbt_pinterest_source/pull/31) includes the following updates:
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_source'
version: '0.10.1'
version: '0.10.2'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
vars:
Expand Down
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: 'pinterest_source_integration_tests'
version: '0.10.1'
version: '0.10.2'
profile: 'integration_tests'
config-version: 2

Expand Down
20 changes: 20 additions & 0 deletions macros/is_table_empty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{%- macro is_table_empty(table_name) -%}

{{ adapter.dispatch('is_table_empty', 'pinterest_source') (table_name) }}

{%- endmacro %}

{%- macro default__is_table_empty(table_name) -%}
{%- if execute and flags.WHICH in ('run', 'build') %}
{% set row_count_query %}
select count(*) as row_count from {{ table_name }}
{% endset %}
{% set results = run_query(row_count_query) %}
{% if results %}
{% set row_count = results.columns[0][0] %}
{% if row_count == 0 %}
{{ return("empty") }}
{% endif %}
{% endif %}
{% endif -%}
{%- endmacro -%}
14 changes: 14 additions & 0 deletions macros/result_if_table_exists.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{%- macro result_if_table_exists(table_ref, result_statement, if_empty=1) -%}

{{ adapter.dispatch('result_if_table_exists', 'pinterest_source') (table_ref, result_statement, if_empty=1) }}

{%- endmacro -%}

{%- macro default__result_if_table_exists(table_ref, result_statement, if_empty=1) -%}
{%- set is_empty_result = pinterest_source.is_table_empty(table_ref) -%}
{%- if is_empty_result == "empty" %}
{{ if_empty }}
{%- else %}
{{ result_statement }}
{%- endif %}
{%- endmacro %}
7 changes: 6 additions & 1 deletion models/stg_pinterest_ads__ad_group_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ final as (
placement_group,
start_time,
summary_status,
row_number() over (partition by source_relation, id order by _fivetran_synced desc) = 1 as is_most_recent_record
{{ pinterest_source.result_if_table_exists(
table_ref=ref('stg_pinterest_ads__ad_group_history_tmp'),
result_statement='row_number() over (partition by id' ~ (', source_relation' if var('pinterest_ads_union_schemas', []) or var('pinterest_ads_union_databases', []) | length > 1) ~ ' order by _fivetran_synced desc)',
if_empty=1
)}} = 1 as is_most_recent_record

from fields
)

Expand Down
7 changes: 6 additions & 1 deletion models/stg_pinterest_ads__advertiser_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ final as (
owner_username,
advertiser_permissions, -- permissions was renamed in macro
updated_time as updated_at,
row_number() over (partition by source_relation, id order by updated_time desc) = 1 as is_most_recent_record
{{ pinterest_source.result_if_table_exists(
table_ref=ref('stg_pinterest_ads__advertiser_history_tmp'),
result_statement='row_number() over (partition by id' ~ (', source_relation' if var('pinterest_ads_union_schemas', []) or var('pinterest_ads_union_databases', []) | length > 1) ~ ' order by updated_time desc)',
if_empty=1
)}} = 1 as is_most_recent_record

from fields
)

Expand Down
7 changes: 6 additions & 1 deletion models/stg_pinterest_ads__campaign_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ final as (
status as campaign_status,
_fivetran_synced,
created_time as created_at,
row_number() over (partition by source_relation, id order by _fivetran_synced desc) = 1 as is_most_recent_record
{{ pinterest_source.result_if_table_exists(
table_ref=ref('stg_pinterest_ads__campaign_history_tmp'),
result_statement='row_number() over (partition by id' ~ (', source_relation' if var('pinterest_ads_union_schemas', []) or var('pinterest_ads_union_databases', []) | length > 1) ~ ' order by _fivetran_synced desc)',
if_empty=1
)}} = 1 as is_most_recent_record

from fields
)

Expand Down
7 changes: 6 additions & 1 deletion models/stg_pinterest_ads__keyword_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ final as (
campaign_id,
match_type,
parent_type,
row_number() over (partition by source_relation, id order by _fivetran_synced desc) = 1 as is_most_recent_record
{{ pinterest_source.result_if_table_exists(
table_ref=ref('stg_pinterest_ads__keyword_history_tmp'),
result_statement='row_number() over (partition by id' ~ (', source_relation' if var('pinterest_ads_union_schemas', []) or var('pinterest_ads_union_databases', []) | length > 1) ~ ' order by _fivetran_synced desc)',
if_empty=1
)}} = 1 as is_most_recent_record

from fields
)

Expand Down
7 changes: 6 additions & 1 deletion models/stg_pinterest_ads__pin_promotion_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ final as (
status as pin_status,
creative_type,
_fivetran_synced,
row_number() over (partition by source_relation, id order by _fivetran_synced desc) = 1 as is_most_recent_record
{{ pinterest_source.result_if_table_exists(
table_ref=ref('stg_pinterest_ads__pin_promotion_history_tmp'),
result_statement='row_number() over (partition by id' ~ (', source_relation' if var('pinterest_ads_union_schemas', []) or var('pinterest_ads_union_databases', []) | length > 1) ~ ' order by _fivetran_synced desc)',
if_empty=1
)}} = 1 as is_most_recent_record

from fields
)

Expand Down