Skip to content

Commit

Permalink
Multiple Appended nth_ever Relationships (#38)
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
tnightengale authored Apr 19, 2023
1 parent 692a4e6 commit eb7f697
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Include in `packages.yml`:
```yaml
packages:
- package: tnightengale/dbt_activity_schema
version: 0.4.0
version: 0.4.1
```
For latest release, see
https://github.com/tnightengale/dbt-activity-schema/releases.
Expand Down
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Project name.
name: 'dbt_activity_schema'
version: '0.4.0'
version: '0.4.1'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]

Expand Down
27 changes: 27 additions & 0 deletions integration_tests/models/nth_ever/dataset__nth_ever_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{
dbt_activity_schema.dataset(
ref("input__nth_ever"),
dbt_activity_schema.activity(
dbt_activity_schema.nth_ever(2),
"visit page",
["activity_occurrence"]
),
[
dbt_activity_schema.activity(
dbt_activity_schema.nth_ever(3),
"visit page",
["activity_occurrence"]
),
dbt_activity_schema.activity(
dbt_activity_schema.nth_ever(4),
"visit page",
["activity_occurrence"]
),
dbt_activity_schema.activity(
dbt_activity_schema.nth_ever(5),
"visit page",
["activity_occurrence"]
),
]
)
}}
9 changes: 9 additions & 0 deletions integration_tests/models/nth_ever/nth_ever.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2

models:
- name: dataset__nth_ever_1

description: A dataset model used to test basic functionality of the `nth_ever` relationship.
tests:
- dbt_utils.equality:
compare_model: ref("output__nth_ever_1")
17 changes: 17 additions & 0 deletions integration_tests/seeds/nth_ever/input__nth_ever.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
activity_id,ts,entity_uuid,activity,anonymous_entity_uuid,feature_json,revenue_impact,link,activity_occurrence,activity_repeated_at
1,2022-01-01 22:10:11,1,visit page,,"{""type"": 1}",0,,1,2022-01-03 22:10:11
2,2022-01-02 22:10:11,1,signed up,,"{""type"": 1}",0,,1,
3,2022-01-03 22:10:11,1,visit page,,"{""type"": 2}",0,,2,2022-01-04 22:10:14
4,2022-01-04 22:10:12,1,added to cart,,"{""type"": 4}",0,,1,2022-01-04 22:10:13
5,2022-01-04 22:10:13,1,added to cart,,"{""type"": 4}",0,,2,
6,2022-01-04 22:10:14,1,visit page,,"{""type"": 2}",0,,3,2022-01-06 22:10:16
7,2022-01-05 22:10:15,1,bought something,,"{""type"": 1}",100,,1,
8,2022-01-06 22:10:16,1,visit page,,"{""type"": 1}",0,,4,
9,2022-01-07 22:10:11,7,visit page,,"{""type"": 1}",0,,1,2022-01-09 22:10:11
10,2022-01-08 22:10:11,7,signed up,,"{""type"": 1}",0,,1,
11,2022-01-09 22:10:11,7,visit page,,"{""type"": 2}",0,,2,2022-01-10 22:10:14
12,2022-01-10 22:10:12,7,added to cart,,"{""type"": 4}",0,,1,2022-01-10 22:10:13
13,2022-01-10 22:10:13,7,added to cart,,"{""type"": 4}",0,,2,
14,2022-01-10 22:10:14,7,visit page,,"{""type"": 2}",0,,3,2022-01-12 22:10:16
15,2022-01-11 22:10:15,7,bought something,,"{""type"": 1}",100,,1,
16,2022-01-12 22:10:16,7,visit page,,"{""type"": 1}",0,,4,
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
activity_occurrence,nth_ever_3_visit_page_activity_occurrence,nth_ever_4_visit_page_activity_occurrence,nth_ever_5_visit_page_activity_occurrence
2,3.000000,4.000000,
2,3.000000,4.000000,
4 changes: 2 additions & 2 deletions macros/dataset.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ filter_activity_stream_using_primary_activity as (
select

-- Primary Activity Columns
{% for col in primary_activity.included_columns %}
{% for col in primary_activity.included_columns + primary_activity.required_columns %}
{{ primary() }}.{{- col }},
{% endfor %}

Expand Down Expand Up @@ -94,7 +94,7 @@ filter_activity_stream_using_primary_activity as (
)

group by
{% for col in primary_activity.included_columns %}
{% for col in primary_activity.included_columns + primary_activity.required_columns %}
{{ primary() }}.{{ col }}{%- if not loop.last -%},{%- endif %}
{% endfor %}
),
Expand Down
9 changes: 8 additions & 1 deletion macros/utils/aliasing/alias_appended_activity.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ params:
The name of the column that will be aliased.
#}

{% set name = activity.relationship.name %}
{% if activity.relationship.name == 'nth_ever' %}
{% set name -%}
{{ name }}_{{ activity.relationship.nth_occurance }}
{%- endset %}
{% endif %}

{% set concatenated_activity_alias %}
{{ activity.relationship.name -}}_{{- activity.name | replace(" ", "_") -}}_{{- column_name -}}
{{ name -}}_{{- activity.name | replace(" ", "_") -}}_{{- column_name -}}
{% endset %}

{% do return(concatenated_activity_alias) %}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbt-activity-schema"
version = "0.4.0"
version = "0.4.1"
description = "A dbt package to create models within the Activity Schema data model framework."
authors = ["Teghan Nightengale <[email protected]>", "Bryce Codell <[email protected]>"]
license = "GNU"
Expand Down

0 comments on commit eb7f697

Please sign in to comment.