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

Release/snowplow attribution/0.2.2 #14

Merged
merged 2 commits into from
Jun 19, 2024
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
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
snowplow-attribution 0.2.2 (2024-06-19)
---------------------------------------
## Summary
This release fixes a bug in the source_checks() macro that could fail if the `snowplow__conversions_source` or `snowplow__conversion_path_source` variables are overwritten. This fix should allow users to provide a `schema.table` or `warehouse.schema.table` style string reference for these sources without having to specify a dbt source in their project (similar to the default), if necessary.

## Fixes
- Fix source checks macro

## Upgrading
Bump the snowplow-unified version in your `packages.yml` file.

snowplow-attribution 0.2.1 (2024-06-11)
---------------------------------------
## Summary
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

name: 'snowplow_attribution'
version: '0.2.1'
version: '0.2.2'
config-version: 2

require-dbt-version: [">=1.6.0", "<2.0.0"]
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: 'snowplow_attribution_integration_tests'
version: '0.2.1'
version: '0.2.2'
config-version: 2

profile: 'integration_tests'
Expand Down
7 changes: 7 additions & 0 deletions macros/attribution_overview.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{#
Copyright (c) 2024-present Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Snowplow Personal and Academic License Version 1.0,
and you may not use this file except in compliance with the Snowplow Personal and Academic License Version 1.0.
You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 at https://docs.snowplow.io/personal-and-academic-license-1.0/
#}

{% macro attribution_overview() %}
{{ return(adapter.dispatch('attribution_overview', 'snowplow_attribution')()) }}
{% endmacro %}
Expand Down
42 changes: 42 additions & 0 deletions macros/get_relation_from_string.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{#
Copyright (c) 2024-present Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Snowplow Personal and Academic License Version 1.0,
and you may not use this file except in compliance with the Snowplow Personal and Academic License Version 1.0.
You may obtain a copy of the Snowplow Personal and Academic License Version 1.0 at https://docs.snowplow.io/personal-and-academic-license-1.0/
#}

/* Macro to allow for hardcoding of the source table reference in var('snowplow__conversion_path_source')
and var('snowplow__conversions_source'). */

{% macro get_relation_from_string(full_table_reference) %}

{% set full_table_reference_without_quotes = full_table_reference | replace("`", "") | replace('"', '') %}
{% set parts = full_table_reference_without_quotes.split('.') %}

{% if parts | length == 3 %}
{% set database = parts[0] %}
{% set schema = parts[1] %}
{% set table = parts[2] %}

{% elif parts | length == 2 %}
{% set database = target.database %}
{% set schema = parts[0] %}
{% set table = parts[1] %}

{% else %}
{{ exceptions.raise_compiler_error(
"Snowplow Error: Compilation error within "~full_table_reference ~". Please make sure you provide a valid table reference that includes a schema."
) }}
{% endif %}

{% set relation = adapter.get_relation(
database=database,
schema=schema,
identifier=table
) %}

{% if relation %}
{{ return(relation) }}
{% endif %}

{% endmacro %}
19 changes: 10 additions & 9 deletions macros/source_checks.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/* Returns the last 'snowplow__path_lookback_steps' number of channels in the path if snowplow__path_lookback_steps > 0,
or the full path otherwise. */
/* Macro to make sure the user does not execute the package with missing conversion or path source data. */

{% macro source_checks() %}
{{ return(adapter.dispatch('source_checks', 'snowplow_attribution')()) }}
{% endmacro %}

{% macro default__source_checks() %}

{%- set __, last_cv_tstamp = snowplow_utils.return_limits_from_model(source('derived', 'snowplow_unified_conversions'),'cv_tstamp','cv_tstamp') %}
{%- set __, last_path_tstamp = snowplow_utils.return_limits_from_model(source('derived', 'snowplow_unified_sessions'),'start_tstamp','start_tstamp') %}
{% set conversions_source_relation = snowplow_attribution.get_relation_from_string(var('snowplow__conversions_source', '')) | default(source('derived', 'snowplow_unified_conversions')) %}
{% set conversion_path_source_relation = snowplow_attribution.get_relation_from_string(var('snowplow__conversion_path_source', '')) | default(source('derived', 'snowplow_unified_views')) %}
{%- set __, last_cv_tstamp = snowplow_utils.return_limits_from_model(conversions_source_relation,'cv_tstamp','cv_tstamp') %}
{%- set __, last_path_tstamp = snowplow_utils.return_limits_from_model(conversion_path_source_relation,'start_tstamp','start_tstamp') %}
{%- set __, last_processed_cv_tstamp = snowplow_utils.return_limits_from_model(this,'cv_path_start_tstamp','cv_path_start_tstamp') %}

{% if is_incremental() %}
{% if last_cv_tstamp < last_processed_cv_tstamp %}
{{ exceptions.raise_compiler_error(
"Snowplow Error: The timestamp of the last conversion event in the conversion souce: " ~ last_cv_tstamp ~
" is lower than the timestamp of the last processed conversion " ~ last_processed_cv_tstamp ~
"within the model snowplow_attribution_paths_to_conversion. Please make sure you have updated downstream sources before proceeding."
) }}
{{ exceptions.raise_compiler_error(
"Snowplow Error: The timestamp of the last conversion event in the conversion source ("~ var('snowplow__conversions_source',source('derived', 'snowplow_unified_conversions')) ~ "):" ~ last_cv_tstamp ~
" is lower than the timestamp of the last processed conversion " ~ last_processed_cv_tstamp ~
"within the model "~ this ~ ". Please make sure you have updated downstream sources before proceeding."
) }}
{% endif %}
{% endif %}

Expand Down
Loading