Skip to content

Commit

Permalink
Merge pull request #13 from bcodell/hotfixes-0.1.3
Browse files Browse the repository at this point in the history
Hotfixes 0.1.3
  • Loading branch information
bcodell authored May 30, 2023
2 parents ee5817e + 8bb9d35 commit d366e19
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "dbt_aql"
version: "0.1.0"
version: "0.1.3"

config-version: 2

Expand Down
20 changes: 20 additions & 0 deletions integration_tests/models/datasets/aql_syntax/dataset__joined.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% set aql %}
using customer_stream
select first visited_page (
activity_id as activity_id,
entity_uuid as customer_id,
ts as first_visited_google_at
filter {{dbt_aql.json_extract('{feature_json}', 'referrer_url')}} = 'google.com'
)
aggregate after bought_something (
count(activity_id) as total_large_purchases_after
join nullif({{dbt_aql.json_extract('{joined}.{feature_json}', 'total_sales')}}, '')::int > 100
)
include (
total_items_purchased_after
)
{% endset %}

-- depends_on: {{ ref('output__joined') }}

{{ dbt_aql.dataset(aql) }}
7 changes: 7 additions & 0 deletions integration_tests/models/datasets/aql_syntax/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ models:
tests:
- dbt_utils.equality:
compare_model: ref("output__filtered")

- name: dataset__joined
description: A test to validate the functionality of join clauses in aql.
tests:
- dbt_utils.equality:
compare_model: ref("output__joined")

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activity_id,customer_id,first_visited_google_at,total_large_purchases_after,total_items_purchased_after
e58cfb189af4fbf30f22821af7aa9316,1,2022-01-01 22:10:11,2,11
fdf62f7ddcd69fc3c3dbd54bf7a34452,7,2022-04-13 22:10:11,0,0
d5d41e942d4b0b5325741007e8814f00,10,2022-01-13 22:10:11,2,18
10 changes: 8 additions & 2 deletions macros/activity_schema/dataset/dataset.sql
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ with
and {{ primary_activity.relationship_clause }}
){% if joined_activities|length > 0 %},{% endif %}
{% for ja in joined_activities %}
{% if ja.filters is not none and (ja.verb, ja.join_condition) != (av.aggregate, jc.all) %}
{% if ja.filters is not none and ja.verb == av.append %}
{{dbt_aql.alias_activity(ja, loop.index)}}{{fs}} as (
select
{%- for column in columns.items() %}
Expand Down Expand Up @@ -141,7 +141,7 @@ with
{{ column.aggfunc(parsed_col) }} as {{ column.alias }}{% if not loop.last -%},{%- endif -%}
{%- endfor %}
from {{primary_activity_alias}} as {{primary}}
left join {% if ja.filters is none %}{{ stream_relation }}{% else %}{{dbt_aql.alias_activity(ja, loop.index)}}{{fs}}{% endif %} {{joined}}
left join {% if ja.filters is not none and ja.verb == av.append %}{{dbt_aql.alias_activity(ja, loop.index)}}{{fs}}{% else %}{{ stream_relation }}{% endif %} {{joined}}
-- filter joined activity first to improve query performance
on {{joined}}.{{columns.activity}} = {{dbt_aql.clean_activity_name(stream, ja.activity_name)}}
{%- if ja.relationship_clause is not none %}
Expand All @@ -157,6 +157,12 @@ with
and {{ej_formatted}}
{%- endfor %}
{%- endif %}
{% if ja.filters is not none and ja.verb == av.aggregate %}
{% for f in ja.filters %}
{%- set f_formatted = f.format(primary=primary, joined=joined, **columns) %}
and {{f_formatted}}
{%- endfor %}
{% endif %}
group by 1
{% else %}
-- special join case for aggregate all to improve performance
Expand Down
2 changes: 1 addition & 1 deletion macros/aql/parse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ be wrapped in a valid aggregation function.
{% macro _parse_filters(query) %}
{%- set ws = dbt_aql.whitespace() -%}
{%- set ws_join = ws~"join"~ws -%}
{%- set query_stripped = query.strip() -%}
{%- set query_stripped = ' '~query.strip() -%}

{%- set join_ixs = modules.re.search(ws_join, query_stripped) -%}
{%- if join_ixs is not none -%}
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-aql"
version = "0.1.0"
version = "0.1.3"
description = "A dbt package to query Activity Streams using a SQL-esque interface."
authors = ["Bryce Codell <[email protected]"]
license = "GNU"
Expand Down

0 comments on commit d366e19

Please sign in to comment.