From fe2d68d032c1176e31572d9aa473d02e951e7c1a Mon Sep 17 00:00:00 2001 From: Teghan Nightengale Date: Tue, 28 Jan 2020 14:20:21 -0500 Subject: [PATCH] WIP: first commit - added aliasing to the unique and not_null schema tests to fix bug where they would fail if model and column had the same name. --- .../global_project/macros/schema_tests/not_null.sql | 4 ++-- .../include/global_project/macros/schema_tests/unique.sql | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) 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 83bf2c28bea..ecab2b2e892 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 @@ -4,8 +4,8 @@ {% set column_name = kwargs.get('column_name', kwargs.get('arg')) %} select count(*) -from {{ model }} -where {{ column_name }} is null +from {{ model }} AS aliased +where aliased.{{ column_name }} is null {% 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 7085c44a7d9..fa8b3567e79 100644 --- a/core/dbt/include/global_project/macros/schema_tests/unique.sql +++ b/core/dbt/include/global_project/macros/schema_tests/unique.sql @@ -7,11 +7,11 @@ select count(*) from ( select - {{ column_name }} + aliased.{{ column_name }} - from {{ model }} - where {{ column_name }} is not null - group by {{ column_name }} + from {{ model }} AS aliased + where aliased.{{ column_name }} is not null + group by aliased.{{ column_name }} having count(*) > 1 ) validation_errors