From 814bf8bf19ab2231061be99cd81fe7a3d91c3cd9 Mon Sep 17 00:00:00 2001 From: Claire Carroll Date: Mon, 29 Jun 2020 09:24:25 -0400 Subject: [PATCH] Ensure surrogate key handles single arg --- integration_tests/data/sql/data_surrogate_key.csv | 10 +++++----- integration_tests/models/sql/schema.yml | 11 +++++++---- integration_tests/models/sql/test_surrogate_key.sql | 8 +++++--- macros/sql/surrogate_key.sql | 3 +-- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/integration_tests/data/sql/data_surrogate_key.csv b/integration_tests/data/sql/data_surrogate_key.csv index 8c858381..bc2f4b01 100644 --- a/integration_tests/data/sql/data_surrogate_key.csv +++ b/integration_tests/data/sql/data_surrogate_key.csv @@ -1,5 +1,5 @@ -field_1,field_2,field_3,expected -a,b,c,7b193b3d33184464106f41ddf733783b -a,,c,c5fd1b92380c6222ab0ef67839208624 -,,c,267743defab4558f1940311b66274e26 -,,,cfab1ba8c67c7c838db98d666f02a132 +column_1,column_2,column_3,expected_column_1_only,expected_all_columns +a,b,c,0cc175b9c0f1b6a831c399e269772661,7b193b3d33184464106f41ddf733783b +a,,c,0cc175b9c0f1b6a831c399e269772661,c5fd1b92380c6222ab0ef67839208624 +,,c,d41d8cd98f00b204e9800998ecf8427e,267743defab4558f1940311b66274e26 +,,,d41d8cd98f00b204e9800998ecf8427e,cfab1ba8c67c7c838db98d666f02a132 diff --git a/integration_tests/models/sql/schema.yml b/integration_tests/models/sql/schema.yml index 0e28b45b..6c6f891b 100644 --- a/integration_tests/models/sql/schema.yml +++ b/integration_tests/models/sql/schema.yml @@ -104,11 +104,14 @@ models: - name: test_surrogate_key tests: - assert_equal: - actual: actual_arguments - expected: expected + actual: actual_column_1_only + expected: expected_column_1_only - assert_equal: - actual: actual_list - expected: expected + actual: actual_all_columns_arguments + expected: expected_all_columns + - assert_equal: + actual: actual_all_columns_list + expected: expected_all_columns - name: test_union tests: diff --git a/integration_tests/models/sql/test_surrogate_key.sql b/integration_tests/models/sql/test_surrogate_key.sql index c6720b56..fd90939f 100644 --- a/integration_tests/models/sql/test_surrogate_key.sql +++ b/integration_tests/models/sql/test_surrogate_key.sql @@ -6,8 +6,10 @@ with data as ( ) select - {{ dbt_utils.surrogate_key('field_1', 'field_2', 'field_3') }} as actual_arguments, - {{ dbt_utils.surrogate_key(['field_1', 'field_2', 'field_3']) }} as actual_list, - expected + {{ dbt_utils.surrogate_key('column_1') }} as actual_column_1_only, + expected_column_1_only, + {{ dbt_utils.surrogate_key('column_1', 'column_2', 'column_3') }} as actual_all_columns_arguments, + {{ dbt_utils.surrogate_key(['column_1', 'column_2', 'column_3']) }} as actual_all_columns_list, + expected_all_columns from data diff --git a/macros/sql/surrogate_key.sql b/macros/sql/surrogate_key.sql index 9e58f7a3..04d38e23 100644 --- a/macros/sql/surrogate_key.sql +++ b/macros/sql/surrogate_key.sql @@ -1,7 +1,6 @@ {%- macro surrogate_key(field_list) -%} - -{%- if varargs|length >= 1 %} +{%- if varargs|length >= 1 or field_list is string %} {%- do exceptions.warn("Warning: the `surrogate_key` macro now takes a single list argument instead of multiple string arguments. Support for multiple string arguments will be deprecated in a future release of dbt-utils.") -%}