From 64773b5cf6cac38428e7243cc65eabac85869e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Coto?= Date: Thu, 6 Jan 2022 04:57:09 +0100 Subject: [PATCH 1/4] Add link for fewer_rows_than schema test in docs (#465) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 70346771..e2f75b0c 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) From 1839747961e7cc62f4ad4c500bbb0c5cdd15634d Mon Sep 17 00:00:00 2001 From: Elize Papineau Date: Thu, 13 Jan 2022 16:08:01 -0800 Subject: [PATCH 2/4] Update get_query_results_as_dict example to demonstrate accessing columnar results as dictionary values (#474) * Update get_qu ery_results_as_dict example to demonstrate accessing columnar results as dictionary values * Use slugify in example * Fix slugify example with dbt_utils. package prefix Co-authored-by: Elize Papineau --- README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e2f75b0c..9570ee54 100644 --- a/README.md +++ b/README.md @@ -658,17 +658,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 @@ -1043,7 +1051,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 %} ... From 51ed999a44fcc7f9f502be11e5f190f5bc84ba4b Mon Sep 17 00:00:00 2001 From: "Joe Ste.Marie" Date: Mon, 17 Jan 2022 23:10:35 -0500 Subject: [PATCH 3/4] Add note about not_null_where deprecation to Readme (#477) * Add note about not_null_where deprecation to Readme * Add docs to unique_where test --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9570ee54..66a3ac99 100644 --- a/README.md +++ b/README.md @@ -229,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 @@ -245,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 From d1a5bac213a51619f6e8d2095c90a221d38d2faa Mon Sep 17 00:00:00 2001 From: Ted Conbeer Date: Fri, 21 Jan 2022 10:43:37 -0700 Subject: [PATCH 4/4] fix: extra brace typo in insert_by_period_materialization --- macros/materializations/insert_by_period_materialization.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 -%}