Skip to content

Commit

Permalink
fix: extra brace typo in insert_by_period_materialization (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
tconbeer authored Feb 18, 2022
1 parent c863448 commit 8b7356b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ For compatibility details between versions of dbt-core and dbt-utils, [see this

**[Schema tests](#schema-tests)**
- [equal_rowcount](#equal_rowcount-source)
- [fewer_rows_than](#fewer_rows_than-source)
- [equality](#equality-source)
- [expression_is_true](#expression_is_true-source)
- [recency](#recency-source)
Expand Down Expand Up @@ -228,6 +229,8 @@ models:
#### unique_where ([source](macros/schema_tests/test_unique_where.sql))
This test validates that there are no duplicate values present in a field for a subset of rows by specifying a `where` clause.

*Warning*: This test is no longer supported. Starting in dbt v0.20.0, the built-in `unique` test supports a `where` config. [See the dbt docs for more details](https://docs.getdbt.com/reference/resource-configs/where).

**Usage:**
```yaml
version: 2
Expand All @@ -244,6 +247,8 @@ models:
#### not_null_where ([source](macros/schema_tests/test_not_null_where.sql))
This test validates that there are no null values present in a column for a subset of rows by specifying a `where` clause.

*Warning*: This test is no longer supported. Starting in dbt v0.20.0, the built-in `not_null` test supports a `where` config. [See the dbt docs for more details](https://docs.getdbt.com/reference/resource-configs/where).

**Usage:**
```yaml
version: 2
Expand Down Expand Up @@ -657,17 +662,25 @@ This macro returns a dictionary from a sql query, so that you don't need to inte

**Usage:**
```
-- Returns a dictionary of the users table where the state is California
{% set california_cities = dbt_utils.get_query_results_as_dict("select * from" ~ ref('cities') ~ "where state = 'CA' and city is not null ") %}
{% set sql_statement %}
select city, state from {{ ref('users) }}
{% endset %}
{%- set places = dbt_utils.get_query_results_as_dict(sql_statement) -%}
select
city,
{% for city in california_cities %}
sum(case when city = {{ city }} then 1 else 0 end) as users_in_{{ city }},
{% endfor %}
count(*) as total
from {{ ref('users') }}
group by 1
{% for city in places['CITY'] | unique -%}
sum(case when city = '{{ city }}' then 1 else 0 end) as users_in_{{ dbt_utils.slugify(city) }},
{% endfor %}
{% for state in places['STATE'] | unique -%}
sum(case when state = '{{ state }}' then 1 else 0 end) as users_in_{{ state }},
{% endfor %}
count(*) as total_total
from {{ ref('users') }}
```

### SQL generators
Expand Down Expand Up @@ -1044,7 +1057,7 @@ select
order_id,
{%- for payment_method in payment_methods %}
sum(case when payment_method = '{{ payment_method }}' then amount end)
as {{ slugify(payment_method) }}_amount,
as {{ dbt_utils.slugify(payment_method) }}_amount,

{% endfor %}
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% materialization insert_by_period, default -%}
{%- set timestamp_field = config.require('timestamp_field') -%}
{%- set start_date = config.require('start_date') -%}
{%- set stop_date = config.get('stop_date') or '' -%}}
{%- set stop_date = config.get('stop_date') or '' -%}
{%- set period = config.get('period') or 'week' -%}

{%- if sql.find('__PERIOD_FILTER__') == -1 -%}
Expand Down

0 comments on commit 8b7356b

Please sign in to comment.