diff --git a/README.md b/README.md index 70346771..66a3ac99 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 @@ -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 @@ -1042,7 +1055,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 %} ... diff --git a/macros/materializations/insert_by_period_materialization.sql b/macros/materializations/insert_by_period_materialization.sql index 851afa3d..5a15c815 100644 --- a/macros/materializations/insert_by_period_materialization.sql +++ b/macros/materializations/insert_by_period_materialization.sql @@ -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 -%}