Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Just picked some options so we can get this merged. Nothing stopping us from continuing to make updates if we change our minds.
  • Loading branch information
dbeatty10 authored Dec 1, 2022
1 parent f56cd0f commit 0f8d3ef
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions website/docs/reference/resource-configs/where.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ tests:
### Custom logic
The rendering context for the `where` config is the same as for all configurations defined in `.yml` files. You have access to `{{ var() }}` and `{{ env_var() }}`, but you **do not** have access to custom macros for setting this config. If you do want to use access custom macros to template out the `where` filter for certain tests, there is a workaround.
The rendering context for the `where` config is the same as for all configurations defined in `.yml` files. You have access to `{{ var() }}` and `{{ env_var() }}`, but you **do not** have access to custom macros for setting this config. If you do want to use custom macros to template out the `where` filter for certain tests, there is a workaround.

As of v0.21, dbt defines a [`get_where_subquery` macro](https://github.com/dbt-labs/dbt-core/blob/main/core/dbt/include/global_project/macros/materializations/tests/where_subquery.sql).

Expand All @@ -137,7 +137,7 @@ You can override this behavior by:

Within this macro definition, you can reference whatever custom macros you want, based on static inputs from the configuration. At simplest, this enables you to DRY up code that you'd otherwise need to repeat across many different `.yml` files. Because the `get_where_subquery` macro is resolved at runtime, your custom macros can also include [fetching the results of introspective database queries](https://docs.getdbt.com/reference/dbt-jinja-functions/run_query).

**Example:** Filter your test to the past three days of data, using dbt's cross-platform `{{ dateadd() }}` utility macro.
**Example:** Filter your test to the past three days of data, using dbt's cross-platform [`dateadd()`](https://docs.getdbt.com/reference/dbt-jinja-functions/cross-database-macros#dateadd) utility macro.

<File name='models/config.yml'>

Expand All @@ -162,7 +162,7 @@ models:
{% set where = config.get('where', '') %}
{% if "__three_days_ago__" in where %}
{# replace placeholder string with result of custom macro #}
{% set three_days_ago = dateadd('day', -3, current_timestamp()) %}
{% set three_days_ago = dbt.dateadd('day', -3, current_timestamp()) %}
{% set where = where | replace("__three_days_ago__", three_days_ago) %}
{% endif %}
{% if where %}
Expand Down

0 comments on commit 0f8d3ef

Please sign in to comment.