Skip to content

Commit

Permalink
Ensure surrogate key handles single arg
Browse files Browse the repository at this point in the history
  • Loading branch information
clrcrl committed Jun 29, 2020
1 parent 7cc5d5b commit 814bf8b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
10 changes: 5 additions & 5 deletions integration_tests/data/sql/data_surrogate_key.csv
Original file line number Diff line number Diff line change
@@ -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
11 changes: 7 additions & 4 deletions integration_tests/models/sql/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions integration_tests/models/sql/test_surrogate_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions macros/sql/surrogate_key.sql
Original file line number Diff line number Diff line change
@@ -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.") -%}

Expand Down

0 comments on commit 814bf8b

Please sign in to comment.