From 04f840d907abfba711a5aad0a2d2e40a714b012e Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Mon, 3 Aug 2020 11:29:20 -0600 Subject: [PATCH] convert tests --- CHANGELOG.md | 1 + .../macros/schema_tests/accepted_values.sql | 8 +++++++- .../global_project/macros/schema_tests/not_null.sql | 8 +++++++- .../global_project/macros/schema_tests/relationships.sql | 8 +++++++- .../include/global_project/macros/schema_tests/unique.sql | 8 +++++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e8f80b23a..6b00096b3a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Features - Added a `dispatch` method to the context adapter and deprecated `adapter_macro`. ([#2302](https://github.com/fishtown-analytics/dbt/issues/2302), [#2679](https://github.com/fishtown-analytics/dbt/pull/2679)) +- The built-in schema tests now use `adapter.dispatch`, so they can be overridden for adapter plugins ([#2415](https://github.com/fishtown-analytics/dbt/issues/2415), [#2684](https://github.com/fishtown-analytics/dbt/pull/2684)) ## dbt 0.18.0b2 (July 30, 2020) diff --git a/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql b/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql index 6dfd43d5cbc..54c8bbcc4dc 100644 --- a/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql +++ b/core/dbt/include/global_project/macros/schema_tests/accepted_values.sql @@ -1,5 +1,5 @@ -{% macro test_accepted_values(model, values) %} +{% macro default__test_accepted_values(model, values) %} {% set column_name = kwargs.get('column_name', kwargs.get('field')) %} {% set quote_values = kwargs.get('quote', True) %} @@ -35,3 +35,9 @@ select count(*) as validation_errors from validation_errors {% endmacro %} + + +{% macro test_accepted_values(model, values) %} + {% set macro = adapter.dispatch('test_accepted_values') %} + {{ macro(model, values, **kwargs) }} +{% endmacro %} diff --git a/core/dbt/include/global_project/macros/schema_tests/not_null.sql b/core/dbt/include/global_project/macros/schema_tests/not_null.sql index 2a6dac26da6..762270fc711 100644 --- a/core/dbt/include/global_project/macros/schema_tests/not_null.sql +++ b/core/dbt/include/global_project/macros/schema_tests/not_null.sql @@ -1,5 +1,5 @@ -{% macro test_not_null(model) %} +{% macro default__test_not_null(model) %} {% set column_name = kwargs.get('column_name', kwargs.get('arg')) %} @@ -9,3 +9,9 @@ where {{ column_name }} is null {% endmacro %} + + +{% macro test_not_null(model) %} + {% set macro = adapter.dispatch('test_not_null') %} + {{ macro(model, **kwargs) }} +{% endmacro %} diff --git a/core/dbt/include/global_project/macros/schema_tests/relationships.sql b/core/dbt/include/global_project/macros/schema_tests/relationships.sql index cd9a820cc1d..74263102431 100644 --- a/core/dbt/include/global_project/macros/schema_tests/relationships.sql +++ b/core/dbt/include/global_project/macros/schema_tests/relationships.sql @@ -1,5 +1,5 @@ -{% macro test_relationships(model, to, field) %} +{% macro default__test_relationships(model, to, field) %} {% set column_name = kwargs.get('column_name', kwargs.get('from')) %} @@ -16,3 +16,9 @@ where child.id is not null {% endmacro %} + + +{% macro test_relationships(model, to, field) %} + {% set macro = adapter.dispatch('test_relationships') %} + {{ macro(model, to, field, **kwargs) }} +{% endmacro %} diff --git a/core/dbt/include/global_project/macros/schema_tests/unique.sql b/core/dbt/include/global_project/macros/schema_tests/unique.sql index 74d63e3d5f9..8787f14f32a 100644 --- a/core/dbt/include/global_project/macros/schema_tests/unique.sql +++ b/core/dbt/include/global_project/macros/schema_tests/unique.sql @@ -1,5 +1,5 @@ -{% macro test_unique(model) %} +{% macro default__test_unique(model) %} {% set column_name = kwargs.get('column_name', kwargs.get('arg')) %} @@ -17,3 +17,9 @@ from ( ) validation_errors {% endmacro %} + + +{% macro test_unique(model) %} + {% set macro = adapter.dispatch('test_unique') %} + {{ macro(model, **kwargs) }} +{% endmacro %}